# rabbitmq_publish – Publish a message to a RabbitMQ queue

New in version 2.8.

- Synopsis

- Requirements

- Parameters

- Notes

- Examples

- Return Values

- Status

## 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 - |  | The body of the message. A `body` cannot be provided if a `src` is specified.
content_type - | Default: "text/plain" | The content type of the body.

durable
boolean

Choices:
- no ←
- yes

Set the queue to be durable.

exchange - |  | 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 - |  | The RabbitMQ server hostname or IP.
password - |  | The RabbitMQ password.
port - |  | The RabbitMQ server port.

proto
-

Choices:
- amqps
- amqp

The protocol to use.

queue - |  | The queue to publish a message to. If no queue is specified, RabbitMQ will return a random queue name.
routing_key - |  | The routing key.
src - |  | 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 - |  | 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 - |  | The RabbitMQ username.
vhost - |  | 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 plugin is tested against RabbitMQ. Other AMQP 0.9.1 protocol based servers may work but not tested/guaranteed.

## Examples

    - name: Publish a message to a queue with headers
      rabbitmq_publish:
        url: "amqp://guest:guest@192.168.0.32: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
      rabbitmq_publish:
        url: "amqp://guest:guest@192.168.0.32:5672/%2F"
        queue: 'images'
        file: 'path/to/logo.gif'

    - name: RabbitMQ auto generated queue
      rabbitmq_publish:
        url: "amqp://guest:guest@192.168.0.32:5672/%2F"
        body: "Hello world random queue from ansible module rabbitmq_publish"
        content_type: "text/plain"

## 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' }

## Status

- This module is not guaranteed to have a backwards compatible interface. [preview]

- This module is maintained by the Ansible Community. [community]

### Authors

- John Imison (@Im0)

Hint

If you notice any issues in this documentation, you can edit this document to improve it.