diff --git a/roles/mosquitto/tasks/main.yml b/roles/mosquitto/tasks/main.yml index 8ad6223..646e1d6 100644 --- a/roles/mosquitto/tasks/main.yml +++ b/roles/mosquitto/tasks/main.yml @@ -5,6 +5,17 @@ tags: - install +- name: ensure mosquitto persistence directory exists + file: + path: '{{ mosquitto_persistence_location }}' + mode: u=rwx,go= + owner: mosquitto + group: mosquitto + state: directory + when: mosquitto_persistence_location|d(none) is not none + tags: + - datadir + - name: ensure mosquitto certificate is installed copy: src: certs/mosquitto/{{ inventory_hostname }}.cer @@ -15,6 +26,8 @@ notify: - restart mosquitto when: mosquitto_certfile is defined + tags: + - cert - name: ensure mosquitto private key is installed copy: src: certs/mosquitto/{{ inventory_hostname }}.key @@ -26,6 +39,8 @@ notify: - restart mosquitto when: mosquitto_keyfile is defined + tags: + - cert - name: ensure mosquitto is configured template: @@ -34,6 +49,8 @@ mode: '0644' notify: - restart mosquitto + tags: + - mosquitto-config - meta: flush_handlers @@ -41,7 +58,11 @@ service: name: mosquitto enabled: true + tags: + - service - name: ensure mosquitto is running service: name: mosquitto state: started + tags: + - service diff --git a/roles/mosquitto/templates/mosquitto.conf.j2 b/roles/mosquitto/templates/mosquitto.conf.j2 index dbbf051..c1416eb 100644 --- a/roles/mosquitto/templates/mosquitto.conf.j2 +++ b/roles/mosquitto/templates/mosquitto.conf.j2 @@ -405,31 +405,51 @@ listener {{ listener.port }} {{ listener.address|d('') }} # autosave_on_changes. # Note that writing of the persistence database can be forced by # sending mosquitto a SIGUSR1 signal. +{% if mosquitto_autosave_interval|d(none) is not none %} +autosave_interval {{ mosquitto_autosave_interval }} +{% else %} #autosave_interval 1800 +{% endif %} # If true, mosquitto will count the number of subscription changes, retained # messages received and queued messages and if the total exceeds # autosave_interval then the in-memory database will be saved to disk. # If false, mosquitto will save the in-memory database to disk by treating # autosave_interval as a time in seconds. +{% if mosquitto_autosave_on_changes|d(none) is not none %} +autosave_on_changes {{ mosquitto_autosave_on_changes|bool|string|lower }} +{% else %} #autosave_on_changes false +{% endif %} # Save persistent message data to disk (true/false). # This saves information about all messages, including # subscriptions, currently in-flight messages and retained # messages. # retained_persistence is a synonym for this option. +{% if mosquitto_persistence|d(none) is not none %} +persistence {{ mosquitto_persistence|bool|string|lower }} +{% else %} #persistence false +{% endif %} # The filename to use for the persistent database, not including # the path. +{% if mosquitto_persistence_file|d(none) is not none %} +persistence_file {{ mosquitto_persistence_file }} +{% else %} #persistence_file mosquitto.db +{% endif %} # Location for persistent database. # Default is an empty string (current directory). # Set to e.g. /var/lib/mosquitto if running as a proper service on Linux or # similar. +{% if mosquitto_persistence_location|d(none) is not none %} +persistence_location {{ mosquitto_persistence_location }} +{% else %} #persistence_location +{% endif %} # =================================================================