community.rabbitmq.rabbitmq_publish module – Publish a message to a RabbitMQ queue.
Note
This module is part of the community.rabbitmq collection (version 1.2.3).
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.rabbitmq
.
You need further requirements to be able to use this module,
see Requirements for details.
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 |
Comments |
---|---|
Set the queue to auto delete. Choices:
|
|
The body of the message. A |
|
CA file used during connection to the RabbitMQ server over SSL. If this option is specified, also certfile and keyfile must be specified. |
|
Client certificate to establish SSL connection. If this option is specified, also cafile and keyfile must be specified. |
|
The content type of the body. Default: |
|
Set the queue to be durable. Choices:
|
|
The exchange to publish a message to. An |
|
Set the queue to be exclusive. Choices:
|
|
A dictionary of headers to post with the message. Default: |
|
The RabbitMQ server hostname or IP. |
|
Client key to establish SSL connection. If this option is specified, also cafile and certfile must be specified. |
|
The RabbitMQ password. |
|
The RabbitMQ server port. |
|
The protocol to use. Choices:
|
|
The queue to publish a message to. If no queue is specified, RabbitMQ will return a random queue name. A |
|
The routing key. |
|
A file to upload to the queue. Automatic mime type detection is attempted if content_type is not defined (left as default). A The filename is added to the headers of the posted message to RabbitMQ. Key being the |
|
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. |
|
The RabbitMQ username. |
|
The virtual host to target. If default vhost is required, use |
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 to an exchange
community.rabbitmq.rabbitmq_publish:
exchange: exchange1
url: "amqp://guest:[email protected]:5672/%2F"
body: "Hello exchange from ansible module rabbitmq_publish"
content_type: "text/plain"
- name: Publish to an exchange with routing_key
community.rabbitmq.rabbitmq_publish:
exchange: exchange1
routing_key: queue1
url: "amqp://guest:[email protected]:5672/%2F"
body: "Hello queue via exchange routing_key from ansible module rabbitmq_publish"
content_type: "text/plain"
- 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 |
Description |
---|---|
If posted to an exchange, the result contains the status msg, content type content_type the exchange name exchange and the routing key routing_key. If posted to a queue, the result contains the status msg, content type content_type and the queue name queue. Returned: success Sample: |