
    Vh                      `    d dl mZmZmZ eZdZdZdZd dl	m
Z
 d dlmZ d Zedk(  r e        y	y	)
    )absolute_importdivisionprint_functionac  
---
module: rabbitmq_publish
short_description: Publish a message to a RabbitMQ queue.
description:
   - Publish a message on a RabbitMQ queue using a blocking connection.
options:
  url:
    description:
      - An URL connection string to connect to the RabbitMQ server.
      - I(url) and I(host)/I(port)/I(user)/I(pass)/I(vhost) are mutually exclusive, use either or but not both.
    type: str
  proto:
    description:
      - The protocol to use.
    type: str
    choices: [amqps, amqp]
  host:
    description:
      - The RabbitMQ server hostname or IP.
    type: str
  port:
    description:
      - The RabbitMQ server port.
    type: int
  username:
    description:
      - The RabbitMQ username.
    type: str
  password:
    description:
      - The RabbitMQ password.
    type: str
  vhost:
    description:
      - The virtual host to target.
      - If default vhost is required, use C('%2F').
    type: str
  queue:
    description:
      - The queue to publish a message to.  If no queue is specified, RabbitMQ will return a random queue name.
      - A C(queue) cannot be provided if an C(exchange) is specified.
    type: str
  exchange:
    description:
      - The exchange to publish a message to.
      - An C(exchange) cannot be provided if a C(queue) is specified.
    type: str
  routing_key:
    description:
      - The routing key.
    type: str
  body:
    description:
      - The body of the message.
      - A C(body) cannot be provided if a C(src) is specified.
    type: str
  src:
    description:
      - A file to upload to the queue.  Automatic mime type detection is attempted if content_type is not defined (left as default).
      - A C(src) cannot be provided if a C(body) is specified.
      - The filename is added to the headers of the posted message to RabbitMQ. Key being the C(filename), value is the filename.
    type: path
    aliases: ['file']
  content_type:
    description:
      - The content type of the body.
    type: str
    default: text/plain
  durable:
    description:
      - Set the queue to be durable.
    type: bool
    default: False
  exclusive:
    description:
      - Set the queue to be exclusive.
    type: bool
    default: False
  auto_delete:
    description:
      - Set the queue to auto delete.
    type: bool
    default: False
  headers:
    description:
      - A dictionary of headers to post with the message.
    type: dict
    default: {}
  cafile:
    description:
      - CA file used during connection to the RabbitMQ server over SSL.
      - If this option is specified, also I(certfile) and I(keyfile) must be specified.
    type: str
  certfile:
    description:
      - Client certificate to establish SSL connection.
      - If this option is specified, also I(cafile) and I(keyfile) must be specified.
    type: str
  keyfile:
    description:
      - Client key to establish SSL connection.
      - If this option is specified, also I(cafile) and I(certfile) must be specified.
    type: str



requirements: [ pika ]
notes:
  - This module requires the pika python library U(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 U(https://www.rabbitmq.com/ssl.html#automated-certificate-generation) and RabbitMQ
    configuration variables C(ssl_options.verify = verify_peer) & C(ssl_options.fail_if_no_peer_cert = true).
author: "John Imison (@Im0)"
aD  
- name: Publish to an exchange
  community.rabbitmq.rabbitmq_publish:
    exchange: exchange1
    url: "amqp://guest:guest@192.168.0.32: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:guest@192.168.0.32: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: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
  community.rabbitmq.rabbitmq_publish:
    url: "amqp://guest:guest@192.168.0.32:5672/%2F"
    queue: 'images'
    file: 'path/to/logo.gif'

- name: RabbitMQ auto generated queue
  community.rabbitmq.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"

- name: Publish with certs
  community.rabbitmq.rabbitmq_publish:
    url: "amqps://guest:guest@192.168.0.32: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'

a  
result:
  description:
    - If posted to an exchange, the result contains the status I(msg), content type I(content_type) the exchange name I(exchange)
    - and the routing key I(routing_key).
    - If posted to a queue, the result contains the status I(msg), content type I(content_type) and the queue name I(queue).
  returned: success
  type: dict
  sample: |
    'result': { 'content_type': 'text/plain', 'msg': 'Successfully published to queue test', 'queue': 'test' }
)AnsibleModule)RabbitClientc                     t        j                         } | j                  t        d      t        ddd      t        dd      t        dgdd      t        d	d
      t        dd
      t        dd
      t        dd
      t        i d
      t        dd      t        dd      t        ddd             t	        | ddgddggg dgd      }t        |      }|j                         r|j                          |j                  9|j                  dd|j                  z  |j                  |j                  d       y |j                  D|j                  dd|j                  z  |j                  |j                  |j                  d       y y |j                          |j                  !|j                  dd|j                  z         y |j                  !|j                  dd|j                  z         y y )Nstr)typeF)r
   requiredno_log)r
   r   filepath)aliasesr
   r   z
text/plain)defaultr
   booldict)exchangerouting_keybodysrccontent_typedurable	exclusiveauto_deleteheaderscafilecertfilekeyfiler   r   queuer   )r   r   r   )argument_specmutually_exclusiverequired_togethersupports_check_modeTz"Successfully published to queue %s)msgr   r   )changedresultz%Successfully published to exchange %s)r$   r   r   r   z#Unsuccessful publishing to queue %s)r%   r$   z&Unsuccessful publishing to exchange %s)r   rabbitmq_argument_specupdater   r   basic_publishclose_connectionr   	exit_jsonr   r   r   	fail_json)r    modulerabbitmqs      w/home/dcms/DCMS/lib/python3.12/site-packages/ansible_collections/community/rabbitmq/plugins/modules/rabbitmq_publish.pymainr0      s    779M5!eeEBuu-&?,U;U0u62V4Rf-/551%%>   ##UOgz-BC<=!	F F#H!!#NN&T:^aiaoao:o&.nnhF[F[3]  +T:adldudu:u,4,@,@hN_N_qy  rG  rG3H  , 	!!#NN&U0UX`XfXf0fg+U0X[c[l[l0lm ,    __main__N)
__future__r   r   r   r
   __metaclass__DOCUMENTATIONEXAMPLESRETURNansible.module_utils.basicr   Dansible_collections.community.rabbitmq.plugins.module_utils.rabbitmqr   r0   __name__ r1   r/   <module>r<      sN    A @tl/b

 5 ])nX zF r1   