--- # Tasks for Mosquitto role - getent: database: passwd key: "{{ mosquitto_user }}" split: ":" - name: Pull Mosquitto image docker_image: name: "{{ mosquitto_image }}" source: pull force_source: yes - name: Ensure Mosquitto Directory exists file: path: "{{ mosquitto_directory }}" state: directory group: 0 # "{{ mosquitto_user }}" owner: 0 # "{{ mosquitto_user }}" mode: 0755 - name: Ensure Mosquitto Config Directory exists file: path: "{{ mosquitto_directory }}/config" state: directory group: 0 # "{{ mosquitto_user }}" owner: 0 # "{{ mosquitto_user }}" mode: 0755 - name: Copy the Mosquitto conf file template: src: "files/mosquitto.conf" dest: "{{ mosquitto_directory }}/config/mosquitto.conf" group: 1883 # "{{ mosquitto_user }}" owner: 1883 # "{{ mosquitto_user }}" mode: 0646 # - name: Check if Mosquitto passwd file exists # stat: path="{{ mosquitto_directory }}/config/passwd" # register: status - name: Ensure Mosquitto passwd file exists template: src: "files/passwd" dest: "{{ mosquitto_directory }}/config/passwd" group: 1883 # "{{ mosquitto_user }}" owner: 1883 # "{{ mosquitto_user }}" mode: 0646 - name: Encrypt the docker file command: docker exec -i mosquitto mosquitto_passwd -U /mosquitto/config/passwd - name: Ensure Mosquitto Log Directory exists file: path: "{{ mosquitto_directory }}/log" state: directory group: 0 # "{{ mosquitto_user }}" owner: 0 # "{{ mosquitto_user }}" mode: 0755 - name: Ensure Mosquitto log file exists file: path: "{{ mosquitto_directory }}/log/mosquitto.log" state: touch group: 0 # "{{ mosquitto_user }}" owner: 0 # "{{ mosquitto_user }}" mode: 0646 - name: Create Mosquitto container docker_container: name: "{{ mosquitto_container }}" image: "{{ mosquitto_image }}" state: started restart_policy: "unless-stopped" # user: 0:0 # "{{ getent_passwd[mosquitto_user][1] }}:{{ getent_passwd[mosquitto_user][2] }}" published_ports: - 127.0.0.1:9001:9001 - 1883:1883 volumes: - "{{ mosquitto_directory }}/config:/mosquitto/config" - "{{ mosquitto_directory }}/data:/mosquitto/data" - "{{ mosquitto_directory }}/log:/mosquitto/log"