commit ada836a23e680f553b64b1dc8bd0468302e92d58
parent 029bd15c5258162923f9ed7e9ed21fc8439c9586
Author: Leah (ctucx) <leah@ctu.cx>
Date: Tue, 23 Feb 2021 15:41:30 +0100
parent 029bd15c5258162923f9ed7e9ed21fc8439c9586
Author: Leah (ctucx) <leah@ctu.cx>
Date: Tue, 23 Feb 2021 15:41:30 +0100
roles/mosquitto: create role
7 files changed, 129 insertions(+), 0 deletions(-)
diff --git a/roles/mosquitto/handlers/main.yml b/roles/mosquitto/handlers/main.yml @@ -0,0 +1,18 @@ +--- + +- name: "[OpenRC] Restart service: mosquitto (to deploy config changes)" + service: + name: mosquitto + state: restarted + when: + - ansible_service_mgr == "openrc" + listen: "Restart mosquitto" + +- name: "[systemd] Restart service: mosquitto (to deploy config changes)" + systemd: + daemon_reload: yes + name: mosquitto + state: restarted + when: + - ansible_service_mgr == "systemd" + listen: "Restart mosquitto"
diff --git a/roles/mosquitto/tasks/configure.yml b/roles/mosquitto/tasks/configure.yml @@ -0,0 +1,10 @@ +--- + +- name: "Create file: /etc/mosquitto/mosquitto.conf" + template: + src: mosquitto.conf.j2 + dest: /etc/mosquitto/mosquitto.conf + mode: "0755" + owner: root + group: root + notify: "Restart mosquitto"
diff --git a/roles/mosquitto/tasks/install.yml b/roles/mosquitto/tasks/install.yml @@ -0,0 +1,15 @@ +--- + +- name: "[Alpine] Install package: mosquitto" + apk: + name: mosquitto + state: present + when: + - ansible_distribution == "Alpine" + +- name: "[Archlinux] Install package: mosquitto" + pacman: + name: mosquitto + state: present + when: + - ansible_distribution == "Archlinux"
diff --git a/roles/mosquitto/tasks/main.yml b/roles/mosquitto/tasks/main.yml @@ -0,0 +1,23 @@ +--- + +- include: install.yml + when: + - services.mosquitto.enable is defined + - services.mosquitto.enable is true + +- include: configure.yml + when: + - services.mosquitto.enable is defined + - services.mosquitto.enable is true + +- include: start.yml + when: + - services.mosquitto.enable is defined + - services.mosquitto.enable is true + +- include: remove.yml + when: + - services.mosquitto.enable is defined + - services.mosquitto.enable is false + +- meta: flush_handlers
diff --git a/roles/mosquitto/tasks/remove.yml b/roles/mosquitto/tasks/remove.yml @@ -0,0 +1,24 @@ +--- + +- name: "[systemd] Disable and stop service: mosquitto" + systemd: + name: "mosquitto" + enabled: no + state: stopped + when: + - ansible_service_mgr == "systemd" + + +- name: "[Archlinux] Remove package: mosquitto" + pacman: + name: mosquitto + state: absent + when: + - ansible_distribution == "Archlinux" + +- name: "Delete leftovers" + file: + path: "{{item}}" + state: absent + with_items: + - /etc/mosquitto
diff --git a/roles/mosquitto/tasks/start.yml b/roles/mosquitto/tasks/start.yml @@ -0,0 +1,17 @@ +--- + +- name: "[OpenRC] Start and enable service: mosquitto" + service: + name: mosquitto + enabled: yes + state: started + when: + - ansible_service_mgr == "openrc" + +- name: "[systemd] Start and enable service: mosquitto" + systemd: + name: mosquitto + enabled: yes + state: started + when: + - ansible_service_mgr == "systemd"+ \ No newline at end of file
diff --git a/roles/mosquitto/templates/mosquitto.conf.j2 b/roles/mosquitto/templates/mosquitto.conf.j2 @@ -0,0 +1,20 @@ +# +# !!! This file is managed by Ansible !!! +# + +# Config file for mosquitto +# +# See mosquitto.conf(5) for more information. +# +# Default values are shown, uncomment to change. +# +# Use the # character to indicate a comment, but only if it is the +# very first character on the line. + +listener {{ services.mosquitto.port | default(1883) }} {{ services.mosquitto.listenAddress | default("0.0.0.0") }} + +{% if services.mosquitto.enableAnonymousLogin is true %} +allow_anonymous true +{% else %} +allow_anonymous false +{% endif %}+ \ No newline at end of file