community.general.mqtt module – Publish a message on an MQTT topic for the IoT
Note
This module is part of the community.general collection (version 8.6.7).
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 module,
see Requirements for details.
To use it in a playbook, specify: community.general.mqtt
.
Synopsis
Publish a message on an MQTT topic.
Aliases: notification.mqtt
Requirements
The below requirements are needed on the host that executes this module.
mosquitto
Parameters
Parameter |
Comments |
---|---|
The path to the Certificate Authority certificate files that are to be treated as trusted by this client. If this is the only option given then the client will operate in a similar manner to a web browser. That is to say it will require the broker to have a certificate signed by the Certificate Authorities in ca_certs and will communicate using TLS v1, but will not attempt any form of authentication. This provides basic network encryption but may not be sufficient depending on how the broker is configured. |
|
The path pointing to the PEM encoded client certificate. If this is not None it will be used as client information for TLS based authentication. Support for this feature is broker dependent. |
|
MQTT client identifier If not specified, a value |
|
The path pointing to the PEM encoded client private key. If this is not None it will be used as client information for TLS based authentication. Support for this feature is broker dependent. |
|
Password for |
|
Payload. The special string |
|
MQTT broker port number Default: |
|
QoS (Quality of Service) Choices:
|
|
Setting this flag causes the broker to retain (i.e. keep) the message so that applications that subsequently subscribe to the topic can received the last retained message immediately. Choices:
|
|
MQTT broker address/name Default: |
|
Specifies the version of the SSL/TLS protocol to be used. By default (if the python version supports it) the highest TLS version is detected. If unavailable, TLS v1 is used. Choices:
|
|
MQTT topic name |
|
Username to authenticate against the broker. |
Attributes
Attribute |
Support |
Description |
---|---|---|
Support: full |
Can run in |
|
Support: none |
Will return details on what has changed (or possibly needs changing in |
Notes
Note
This module requires a connection to an MQTT broker such as Mosquitto http://mosquitto.org and the Paho
mqtt
Python client (https://pypi.org/project/paho-mqtt/).
Examples
- name: Publish a message on an MQTT topic
community.general.mqtt:
topic: 'service/ansible/{{ ansible_hostname }}'
payload: 'Hello at {{ ansible_date_time.iso8601 }}'
qos: 0
retain: false
client_id: ans001
delegate_to: localhost