diff --git a/inventories/thinkcccentre/host_vars/automation.yml b/inventories/thinkcccentre/host_vars/automation.yml new file mode 100644 index 0000000..f49c9c1 --- /dev/null +++ b/inventories/thinkcccentre/host_vars/automation.yml @@ -0,0 +1,4 @@ +mosquitto__mosquitto_conf_content: "{{ lookup('ansible.builtin.file', 'configs/automation/mosquitto/mosquitto.conf') }}" +mosquitto__configs: + - name: winkekatz + content: "{{ lookup('ansible.builtin.file', 'configs/automation/mosquitto/winkekatz.conf') }}" diff --git a/playbooks/deploy_automation.yml b/playbooks/deploy_automation.yml new file mode 100644 index 0000000..d858029 --- /dev/null +++ b/playbooks/deploy_automation.yml @@ -0,0 +1,6 @@ +--- +- name: Deploy mosquitto MQTT broker on automation.z9 + become: true + hosts: automation + roles: + - mosquitto diff --git a/playbooks/files/configs/automation/mosquitto/mosquitto.conf b/playbooks/files/configs/automation/mosquitto/mosquitto.conf new file mode 100644 index 0000000..05141ab --- /dev/null +++ b/playbooks/files/configs/automation/mosquitto/mosquitto.conf @@ -0,0 +1,16 @@ +# Place your local configuration in /etc/mosquitto/conf.d/ +# +# A full description of the configuration file is at +# /usr/share/doc/mosquitto/examples/mosquitto.conf.example + +per_listener_settings false +listener 1883 +allow_anonymous true +pid_file /run/mosquitto/mosquitto.pid + +persistence true +persistence_location /var/lib/mosquitto/ + +log_dest file /var/log/mosquitto/mosquitto.log + +include_dir /etc/mosquitto/conf.d diff --git a/playbooks/files/configs/automation/mosquitto/winkekatz.conf b/playbooks/files/configs/automation/mosquitto/winkekatz.conf new file mode 100644 index 0000000..975ff05 --- /dev/null +++ b/playbooks/files/configs/automation/mosquitto/winkekatz.conf @@ -0,0 +1,10 @@ +connection winkekatz +address mqtt.winkekatze24.de +topic winkekatze/# both +bridge_protocol_version mqttv311 + +topic "" in 2 devices/katz9/eyecolor/eyecolor/set jimmykater/eye/set +topic "" in 2 devices/katz9/command/wink/set winkekatze/allcats +topic "" out 2 devices/katz9/command/status katz9/status +topic "" out 2 devices/katz9/$online katz9/connected +topic "" in 2 devices/katz9/command/wink/set katz9/command diff --git a/playbooks/roles/mosquitto/handlers/main.yml b/playbooks/roles/mosquitto/handlers/main.yml new file mode 100644 index 0000000..94fba82 --- /dev/null +++ b/playbooks/roles/mosquitto/handlers/main.yml @@ -0,0 +1,5 @@ +--- +- name: Restart mosquitto + ansible.builtin.systemd: + service: mosquitto.service + state: restarted diff --git a/playbooks/roles/mosquitto/meta/argument_specs.yml b/playbooks/roles/mosquitto/meta/argument_specs.yml new file mode 100644 index 0000000..72f0bdd --- /dev/null +++ b/playbooks/roles/mosquitto/meta/argument_specs.yml @@ -0,0 +1,26 @@ +--- +argument_specs: + main: + options: + mosquitto__mosquitto_conf_content: + description: The content of the main mosquitto configuration file. + type: str + required: true + mosquitto__configs: + description: A list of additional mosquitto configurations. + type: list + elements: dict + required: false + options: + name: + description: >- + The name of the configuration file, where the configuration should + be deployed to. The file will be placed under `/etc/mosquitto/conf.d` and + `.conf` will be appended to the given name. So in the end the path + will be like this: `/etc/mosquitto/conf.d/\{\ name \}\}.conf`. + type: str + required: true + content: + description: The content of the configuration. + type: str + required: true diff --git a/playbooks/roles/mosquitto/meta/main.yml b/playbooks/roles/mosquitto/meta/main.yml new file mode 100644 index 0000000..2c3bd99 --- /dev/null +++ b/playbooks/roles/mosquitto/meta/main.yml @@ -0,0 +1,8 @@ +--- +dependencies: + - role: distribution_check + vars: + distribution_check__supported_distributions: + - name: Debian + versions: + - "11" diff --git a/playbooks/roles/mosquitto/tasks/main.yml b/playbooks/roles/mosquitto/tasks/main.yml new file mode 100644 index 0000000..5d8e145 --- /dev/null +++ b/playbooks/roles/mosquitto/tasks/main.yml @@ -0,0 +1,26 @@ +--- +- name: Ensure mosquitto is installed + ansible.builtin.apt: + name: mosquitto +- name: Ensure main configuraton file is deployed + ansible.builtin.copy: + content: "{{ mosquitto__mosquitto_conf_content }}" + dest: /etc/mosquitto/mosquitto.conf + mode: 0644 + owner: root + group: root + notify: Restart mosquitto +- name: Ensure all additional configuraton files are deployed + ansible.builtin.copy: + content: "{{ item.content }}" + dest: /etc/mosquitto/conf.d/{{ item.name }}.conf + mode: 0644 + owner: root + group: root + loop: "{{ mosquitto__configs }}" + notify: Restart mosquitto +- name: Ensure mosquitto service is enabled and started + ansible.builtin.systemd: + service: mosquitto.service + enabled: true + state: started