Skip to content

Ansible role to install and configure Mosquitto MQTT broker.

License

Notifications You must be signed in to change notification settings

oscarcarlsson/ansible-role-mosquitto

 
 

Repository files navigation

Ansible Role: Mosquitto

Build Status Ansible Galaxy

Install and configure Mosquitto MQTT message broker. Forked from lnovara/ansible-mosquitto.

Requirements

An Ansible 2.2 or higher installation.

Role Variables

Available variables are listed below, along with default values (see defaults/main.yml).

mosquitto_packages:
  - mosquitto
  - mosquitto-clients

Packages to install for Mosquitto.

mosquitto_python_packages:
  - paho-mqtt

Python packages to install for Mosquitto.

mosquitto_user: mosquitto
mosquitto_group: mosquitto

Mosquitto system user and group.

mosquitto_home: /var/lib/mosquitto

Mosquitto user home directory.

mosquitto_add_groups: []

Additional groups for Mosquitto user.

mosquitto_config_file: /etc/mosquitto/mosquitto.conf

Path to Mosquitto configuration file

mosquitto_config: {}

Dictionary holding Mosquitto configuration. The complete Mosquitto configuration reference can be found here.
NOTE: the provided Mosquitto configuration will be merged with the default one defined in vars/main.yml.

mosquitto_listeners: []

Example:

mosquitto_listeners:
  - listener: "1883 localhost"
    protocol: mqtt
    use_username_as_clientid: true

List holding Mosquitto listeners configuration.

mosquitto_bridges: []

Example:

mosquitto_bridges:
  - connection: bridge_name
    address: exmaple.com:1883
    topics:
      - "topic foobar/# in"
      - "topic baz/# out"'

List holding Mosquitto bridges configuration.

mosquitto_auth_anonymous: []

mosquitto_auth_users: []

mosquitto_auth_patterns: []

Examples:

mosquitto_auth_anonymous:
  - "topic read topic_name"

mosquitto_auth_users:
  - name: user_name
    state: present
    psk: zfEGZkTMPOhxNBTe # Optional. Needs mosquitto_config.psk_file set.
    acl:
      - "topic read topic1_name"
      - "topic readwrite topic2_name"

mosquitto_auth_patterns:
  - "pattern write $SYS/broker/connection/%c/state"

Lists holding Mosquitto ACLs.

mosquitto_certificates: {}

Dictionary holding certificate configuration.

Example:

mosquitto_certificates:
 - name: "cert"
   path: "/etc/mosquitto/certs/mosquitto.crt"
   content: |
     -----BEGIN CERTIFICATE-----
     -----END CERTIFICATE-----

 - name: "key"
   path: "/etc/mosquitto/certs/mosquitto.key"
   content: |
     -----BEGIN PRIVATE KEY-----
     -----END CERTIFICATE-----

 - name: "ca"
   path: "/etc/mosquitto/certs/ca.crt"
   content: |
     -----BEGIN CERTIFICATE-----
     -----END CERTIFICATE-----

Configuration for a custom dhparam file for mosquitto, will be generated if it doesn't exist.

mosquitto_dhparam_file: /etc/mosquitto/dhparam.pem
mosquitto_dhparam_keysize: 2048

Dependencies

None.

Example Playbook

- name: Install and configure Mosquitto on all hosts.
  hosts: all
  roles:
     - lnovara.mosquitto

Testing

This role uses molecule to implement automatic testing of its functionalities.

To execute the tests

pip install tox

git clone https://github.com/lnovara/ansible-mosquitto.git

cd ansible-mosquitto

# test all the scenarios
tox

License

MIT

Author Information

Luca Novara

About

Ansible role to install and configure Mosquitto MQTT broker.

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages

  • Jinja 72.6%
  • Python 27.4%