diff --git a/inventories/z9/host_vars/zigbee2mqtt.yaml b/inventories/z9/host_vars/zigbee2mqtt.yaml index 76f46bb..b154f64 100644 --- a/inventories/z9/host_vars/zigbee2mqtt.yaml +++ b/inventories/z9/host_vars/zigbee2mqtt.yaml @@ -9,7 +9,7 @@ zigbee2mqtt__network_key: !vault | 63343465333062636637313130306434623565623561303835303934306239623035323333323333 30303031306635313764323434333465353465366633376432326563666264386431623335613636 64643434666433363865 -zigbee2mqtt__config: "{{ lookup('ansible.builtin.template', 'configs/zigbee2mqtt/zigbee2mqtt/configuration.yaml.j2') }}" +zigbee2mqtt__initial_config: "{{ lookup('ansible.builtin.template', 'configs/zigbee2mqtt/zigbee2mqtt/configuration.yaml.j2') }}" nginx__version_spec: "" nginx__configurations: - name: zigbee2mqtt diff --git a/playbooks/roles/zigbee2mqtt/meta/argument_specs.yaml b/playbooks/roles/zigbee2mqtt/meta/argument_specs.yaml index d0aab1f..54ab016 100644 --- a/playbooks/roles/zigbee2mqtt/meta/argument_specs.yaml +++ b/playbooks/roles/zigbee2mqtt/meta/argument_specs.yaml @@ -6,7 +6,8 @@ argument_specs: description: zigbee2mqtt version to install type: str required: true - zigbee2mqtt__config: - description: Configuration file content + zigbee2mqtt__initial_config: + description: Configuration file content for initial deployment. + It does not replace the configuration if it already exists. type: str required: true diff --git a/playbooks/roles/zigbee2mqtt/tasks/main.yaml b/playbooks/roles/zigbee2mqtt/tasks/main.yaml index 619e108..f647f03 100644 --- a/playbooks/roles/zigbee2mqtt/tasks/main.yaml +++ b/playbooks/roles/zigbee2mqtt/tasks/main.yaml @@ -1,9 +1,11 @@ - name: Ensure acl is installed ansible.builtin.apt: name: acl + - name: Ensure git is installed ansible.builtin.apt: name: git + - name: Ensure zigbee2mqtt user exists ansible.builtin.user: name: zigbee2mqtt @@ -11,13 +13,15 @@ - zigbee2mqtt - dialout group: zigbee2mqtt -- name: Ensure installation dirrectory exists + +- name: Ensure installation directory exists ansible.builtin.file: dest: /opt/zigbee2mqtt state: directory - mode: 0755 + mode: "755" owner: zigbee2mqtt group: zigbee2mqtt + - name: Ensure zigbee2mqtt repository is cloned become_user: zigbee2mqtt ansible.builtin.git: @@ -26,35 +30,46 @@ dest: /opt/zigbee2mqtt version: "{{ zigbee2mqtt__version }}" notify: Restart zigbee2mqtt + - name: Ensure npm dependencies are installed become_user: zigbee2mqtt community.general.npm: path: /opt/zigbee2mqtt ci: true changed_when: false # installs packages according to package-lock.json, but always reports a change + - name: Ensure custom zigbee2mqtt data directory exists ansible.builtin.file: dest: /home/zigbee2mqtt/zigbee2mqtt_data state: directory - mode: 0755 + mode: "755" owner: zigbee2mqtt group: zigbee2mqtt -- name: Ensure configuration file is deployed + +- name: Check configuration file status + ansible.builtin.stat: + path: /home/zigbee2mqtt/zigbee2mqtt_data/configuration.yaml + register: zigbee2mqtt__conf_stat + +- name: Ensure configuration file is deployed when it doesn't exist + when: not zigbee2mqtt__conf_stat.stat.exists ansible.builtin.copy: content: "{{ zigbee2mqtt__config }}" dest: /home/zigbee2mqtt/zigbee2mqtt_data/configuration.yaml - mode: 0640 + mode: "640" owner: zigbee2mqtt group: zigbee2mqtt notify: Restart zigbee2mqtt + - name: Ensure zigbee2mqtt service file is deployed ansible.builtin.copy: src: zigbee2mqtt.service dest: /etc/systemd/system/zigbee2mqtt.service - mode: 0644 + mode: "644" owner: root group: root notify: Reload systemd-daemon and restart zigbee2mqtt + - name: Ensure zigbee2mqtt is enabled and started ansible.builtin.systemd: service: zigbee2mqtt