community.general.logstash callback – Sends events to Logstash

Note

This callback plugin is part of the community.general collection (version 14.0.0).

You might already have this collection installed if you are using the ansible package. It is not included in ansible-core. To check whether it is installed, run ansible-galaxy collection list.

To install it, use: ansible-galaxy collection install community.general. You need further requirements to be able to use this callback plugin, see Requirements for details.

To use it in a playbook, specify: community.general.logstash.

Callback plugin

This plugin is a notification callback. It sends information for a playbook run to other applications, services, or systems. See Callback plugins for more information on callback plugins.

Synopsis

Requirements

The below requirements are needed on the local controller node that executes this callback.

  • whitelisting in configuration

  • logstash (Python library)

Parameters

Parameter

Comments

ca_path

path

added in community.general 14.0.0

PEM-formatted file containing the CA certificate used to validate the Logstash server. This option is used only with protocol=https.

Configuration:

client_cert

path

added in community.general 14.0.0

PEM-formatted certificate chain file for TLS client authentication. This option is used only with protocol=https.

Configuration:

client_key

path

added in community.general 14.0.0

PEM-formatted private key file for TLS client authentication. The key can also be included in client_cert. This option is used only with protocol=https.

Configuration:

format_version

string

added in community.general 2.0.0

Logging format. Used with all protocol choices.

Choices:

  • "v1" ← (default)

  • "v2"

Configuration:

http_path

string

added in community.general 14.0.0

HTTP request path, for example when sending events through a reverse proxy. This option is used only with protocol=http or protocol=https.

Default: "/"

Configuration:

password

string

added in community.general 14.0.0

Password for HTTP Basic authentication. This option is used only with protocol=http or protocol=https, and must be set together with username. Use HTTPS to protect credentials and events in transit.

Configuration:

port

integer

Port on which Logstash is listening. Used with all protocol choices.

Default: 5000

Configuration:

  • INI entry:

    [callback_logstash]
    port = 5000
    

    added in community.general 1.0.0

  • Environment variable: LOGSTASH_PORT

  • Environment variable: ANSIBLE_CALLBACK_LOGSTASH_PORT

    added in community.general 14.0.0

  • Variable: ansible_callback_logstash_port

    added in community.general 14.0.0

pre_command

string

added in community.general 2.0.0

Executes command before run and adds its result to the ansible_pre_command_output Logstash field. Used with all protocol choices.

Configuration:

protocol

string

added in community.general 14.0.0

Transport protocol to use when sending events to Logstash.

Choices:

  • "tcp" ← (default)

  • "http"

  • "https"

Configuration:

retries

integer

added in community.general 14.0.0

Number of retries for HTTP 429 (Too Many Requests) responses. Uses exponential backoff with jitter between attempts. This option is used only with protocol=http or protocol=https.

Default: 3

Configuration:

server

string

Address of the Logstash server. Used with all protocol choices.

Default: "localhost"

Configuration:

  • INI entry:

    [callback_logstash]
    server = localhost
    

    added in community.general 1.0.0

  • Environment variable: LOGSTASH_SERVER

  • Environment variable: ANSIBLE_CALLBACK_LOGSTASH_SERVER

    added in community.general 14.0.0

  • Variable: ansible_callback_logstash_server

    added in community.general 14.0.0

timeout

integer

added in community.general 14.0.0

Maximum time in seconds to wait for an HTTP request to complete. This option is used only with protocol=http or protocol=https.

Default: 10

Configuration:

type

string

Message type. Used with all protocol choices.

Default: "ansible"

Configuration:

  • INI entry:

    [callback_logstash]
    type = ansible
    

    added in community.general 1.0.0

  • Environment variable: LOGSTASH_TYPE

  • Environment variable: ANSIBLE_CALLBACK_LOGSTASH_TYPE

    added in community.general 14.0.0

  • Variable: ansible_callback_logstash_type

    added in community.general 14.0.0

username

string

added in community.general 14.0.0

Username for HTTP Basic authentication. This option is used only with protocol=http or protocol=https, and must be set together with password.

Configuration:

validate_certs

boolean

added in community.general 14.0.0

Whether to validate the TLS certificate of the Logstash server. This option is used only with protocol=https.

Choices:

  • false

  • true ← (default)

Configuration:

Note

Configuration entries listed above for each entry type (Ansible variable, environment variable, and so on) have a low to high priority order. For example, a variable that is lower in the list will override a variable that is higher up. The entry types are also ordered by precedence from low to high priority order. For example, an ansible.cfg entry (further up in the list) is overwritten by an Ansible variable (further down in the list).

Examples

ansible.cfg: |
  # Enable Callback plugin
  [defaults]
      callback_whitelist = community.general.logstash

  [callback_logstash]
      server = logstash.example.com
      port = 5000
      protocol = tcp
      pre_command = git rev-parse HEAD
      type = ansible

ansible.cfg (HTTPS with Basic authentication): |
  # Store the password in ANSIBLE_CALLBACK_LOGSTASH_PASSWORD or a secrets manager, not in this file
  [defaults]
      callbacks_enabled = community.general.logstash

  [callback_logstash]
      protocol = https
      server = logstash.example.com
      port = 8080
      http_path = /
      username = ansible

11-input-http.conf: |-
  # Enable Logstash HTTP Input
  input {
    http {
      port => 8080
      user => "${LOGSTASH_HTTP_USER}"
      password => "${LOGSTASH_HTTP_PASSWORD}"
      ssl_enabled => true
      ssl_certificate => "/etc/logstash/server.crt"
      ssl_key => "/etc/logstash/server.pkcs8.key"
    }
  }

11-input-tcp.conf: |-
  # Enable Logstash TCP Input
  input {
    tcp {
      port => 5000
      codec => json
      add_field => { "[@metadata][beat]" => "notify" }
      add_field => { "[@metadata][type]" => "ansible" }
    }
  }

Authors

  • Yevhen Khmelenko (@ujenmr)