--- - block: - name: Install mqtt packages package: name: mosquitto state: present - name: Create group '{{ mosquitto_group }}' group: name: '{{ mosquitto_group }}' state: present - name: Create user '{{ mosquitto_user }}' user: name: '{{ mosquitto_user }}' group: '{{ mosquitto_group }}' home: "{{ mosquitto_base_dir }}" system: yes shell: /sbin/nologin - name: Deploy default configuration template: src: "etc/mosquitto/mosquitto.conf.j2" dest: "{{ mosquitto_base_dir }}/mosquitto.conf" owner: root group: root mode: 0644 notify: __mosquitto_restart - name: Open port in iptables iptables_raw: name: allow_mosquitto_port state: present rules: - '-A OUTPUT -m state --state NEW -p tcp --dport {{ mosquitto_port }} -j ACCEPT' - '-A INPUT -m state --state NEW -p tcp --dport {{ mosquitto_port }} -j ACCEPT' when: mosquitto_iptables_enabled become: True become_user: root