W3cubDocs

/Ansible 2.10

community.rabbitmq.rabbitmq_publish – Publish a message to a RabbitMQ queue.

Note

This plugin is part of the community.rabbitmq collection.

To install it use: ansible-galaxy collection install community.rabbitmq.

To use it in a playbook, specify: community.rabbitmq.rabbitmq_publish.

Synopsis

  • Publish a message on a RabbitMQ queue using a blocking connection.

Requirements

The below requirements are needed on the host that executes this module.

  • pika

Parameters

Parameter Choices/Defaults Comments
auto_delete
boolean
    Choices:
  • no
  • yes
Set the queue to auto delete.
body
string
The body of the message.
A body cannot be provided if a src is specified.
cafile
string
CA file used during connection to the RabbitMQ server over SSL.
If this option is specified, also certfile and keyfile must be specified.
certfile
string
Client certificate to establish SSL connection.
If this option is specified, also cafile and keyfile must be specified.
content_type
string
Default:
"text/plain"
The content type of the body.
durable
boolean
    Choices:
  • no
  • yes
Set the queue to be durable.
exchange
string
The exchange to publish a message to.
exclusive
boolean
    Choices:
  • no
  • yes
Set the queue to be exclusive.
headers
dictionary
Default:
{}
A dictionary of headers to post with the message.
host
string
The RabbitMQ server hostname or IP.
keyfile
string
Client key to establish SSL connection.
If this option is specified, also cafile and certfile must be specified.
password
string
The RabbitMQ password.
port
integer
The RabbitMQ server port.
proto
string
    Choices:
  • amqps
  • amqp
The protocol to use.
queue
string
The queue to publish a message to. If no queue is specified, RabbitMQ will return a random queue name.
routing_key
string
The routing key.
src
path
A file to upload to the queue. Automatic mime type detection is attempted if content_type is not defined (left as default).
A src cannot be provided if a body is specified.
The filename is added to the headers of the posted message to RabbitMQ. Key being the filename, value is the filename.

aliases: file
url
string
An URL connection string to connect to the RabbitMQ server.
url and host/port/user/pass/vhost are mutually exclusive, use either or but not both.
username
string
The RabbitMQ username.
vhost
string
The virtual host to target.
If default vhost is required, use '%2F'.

Notes

Note

  • This module requires the pika python library https://pika.readthedocs.io/.
  • Pika is a pure-Python implementation of the AMQP 0-9-1 protocol that tries to stay fairly independent of the underlying network support library.
  • This module is tested against RabbitMQ. Other AMQP 0.9.1 protocol based servers may work but not tested/guaranteed.
  • The certificate authentication was tested with certificates created via https://www.rabbitmq.com/ssl.html#automated-certificate-generation and RabbitMQ configuration variables ssl_options.verify = verify_peer & ssl_options.fail_if_no_peer_cert = true.

Examples

- name: Publish a message to a queue with headers
  community.rabbitmq.rabbitmq_publish:
    url: "amqp://guest:[email protected]:5672/%2F"
    queue: 'test'
    body: "Hello world from ansible module rabbitmq_publish"
    content_type: "text/plain"
    headers:
      myHeader: myHeaderValue


- name: Publish a file to a queue
  community.rabbitmq.rabbitmq_publish:
    url: "amqp://guest:[email protected]:5672/%2F"
    queue: 'images'
    file: 'path/to/logo.gif'

- name: RabbitMQ auto generated queue
  community.rabbitmq.rabbitmq_publish:
    url: "amqp://guest:[email protected]:5672/%2F"
    body: "Hello world random queue from ansible module rabbitmq_publish"
    content_type: "text/plain"

- name: Publish with certs
  community.rabbitmq.rabbitmq_publish:
    url: "amqps://guest:[email protected]:5671/%2F"
    body: "Hello test queue from ansible module rabbitmq_publish via SSL certs"
    queue: 'test'
    content_type: "text/plain"
    cafile: 'ca_certificate.pem'
    certfile: 'client_certificate.pem'
    keyfile: 'client_key.pem'

Return Values

Common return values are documented here, the following are the fields unique to this module:

Key Returned Description
result
dictionary
success
Contains the status msg, content type content_type and the queue name queue.

Sample:
'result': { 'content_type': 'text/plain', 'msg': 'Successfully published to queue test', 'queue': 'test' }


Authors

  • John Imison (@Im0)

© 2012–2018 Michael DeHaan
© 2018–2019 Red Hat, Inc.
Licensed under the GNU General Public License version 3.
https://docs.ansible.com/ansible/2.10/collections/community/rabbitmq/rabbitmq_publish_module.html