Only deploy zigbee2mqtt config when it doesn't exist

This commit is contained in:
yuri 2023-05-09 14:39:50 +02:00
parent 048e189828
commit 9dc77ad5a5
No known key found for this signature in database
GPG key ID: E646779AC54AEC64
3 changed files with 25 additions and 9 deletions

View file

@ -9,7 +9,7 @@ zigbee2mqtt__network_key: !vault |
63343465333062636637313130306434623565623561303835303934306239623035323333323333 63343465333062636637313130306434623565623561303835303934306239623035323333323333
30303031306635313764323434333465353465366633376432326563666264386431623335613636 30303031306635313764323434333465353465366633376432326563666264386431623335613636
64643434666433363865 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__version_spec: ""
nginx__configurations: nginx__configurations:
- name: zigbee2mqtt - name: zigbee2mqtt

View file

@ -6,7 +6,8 @@ argument_specs:
description: zigbee2mqtt version to install description: zigbee2mqtt version to install
type: str type: str
required: true required: true
zigbee2mqtt__config: zigbee2mqtt__initial_config:
description: Configuration file content description: Configuration file content for initial deployment.
It does not replace the configuration if it already exists.
type: str type: str
required: true required: true

View file

@ -1,9 +1,11 @@
- name: Ensure acl is installed - name: Ensure acl is installed
ansible.builtin.apt: ansible.builtin.apt:
name: acl name: acl
- name: Ensure git is installed - name: Ensure git is installed
ansible.builtin.apt: ansible.builtin.apt:
name: git name: git
- name: Ensure zigbee2mqtt user exists - name: Ensure zigbee2mqtt user exists
ansible.builtin.user: ansible.builtin.user:
name: zigbee2mqtt name: zigbee2mqtt
@ -11,13 +13,15 @@
- zigbee2mqtt - zigbee2mqtt
- dialout - dialout
group: zigbee2mqtt group: zigbee2mqtt
- name: Ensure installation dirrectory exists
- name: Ensure installation directory exists
ansible.builtin.file: ansible.builtin.file:
dest: /opt/zigbee2mqtt dest: /opt/zigbee2mqtt
state: directory state: directory
mode: 0755 mode: "755"
owner: zigbee2mqtt owner: zigbee2mqtt
group: zigbee2mqtt group: zigbee2mqtt
- name: Ensure zigbee2mqtt repository is cloned - name: Ensure zigbee2mqtt repository is cloned
become_user: zigbee2mqtt become_user: zigbee2mqtt
ansible.builtin.git: ansible.builtin.git:
@ -26,35 +30,46 @@
dest: /opt/zigbee2mqtt dest: /opt/zigbee2mqtt
version: "{{ zigbee2mqtt__version }}" version: "{{ zigbee2mqtt__version }}"
notify: Restart zigbee2mqtt notify: Restart zigbee2mqtt
- name: Ensure npm dependencies are installed - name: Ensure npm dependencies are installed
become_user: zigbee2mqtt become_user: zigbee2mqtt
community.general.npm: community.general.npm:
path: /opt/zigbee2mqtt path: /opt/zigbee2mqtt
ci: true ci: true
changed_when: false # installs packages according to package-lock.json, but always reports a change changed_when: false # installs packages according to package-lock.json, but always reports a change
- name: Ensure custom zigbee2mqtt data directory exists - name: Ensure custom zigbee2mqtt data directory exists
ansible.builtin.file: ansible.builtin.file:
dest: /home/zigbee2mqtt/zigbee2mqtt_data dest: /home/zigbee2mqtt/zigbee2mqtt_data
state: directory state: directory
mode: 0755 mode: "755"
owner: zigbee2mqtt owner: zigbee2mqtt
group: 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: ansible.builtin.copy:
content: "{{ zigbee2mqtt__config }}" content: "{{ zigbee2mqtt__config }}"
dest: /home/zigbee2mqtt/zigbee2mqtt_data/configuration.yaml dest: /home/zigbee2mqtt/zigbee2mqtt_data/configuration.yaml
mode: 0640 mode: "640"
owner: zigbee2mqtt owner: zigbee2mqtt
group: zigbee2mqtt group: zigbee2mqtt
notify: Restart zigbee2mqtt notify: Restart zigbee2mqtt
- name: Ensure zigbee2mqtt service file is deployed - name: Ensure zigbee2mqtt service file is deployed
ansible.builtin.copy: ansible.builtin.copy:
src: zigbee2mqtt.service src: zigbee2mqtt.service
dest: /etc/systemd/system/zigbee2mqtt.service dest: /etc/systemd/system/zigbee2mqtt.service
mode: 0644 mode: "644"
owner: root owner: root
group: root group: root
notify: Reload systemd-daemon and restart zigbee2mqtt notify: Reload systemd-daemon and restart zigbee2mqtt
- name: Ensure zigbee2mqtt is enabled and started - name: Ensure zigbee2mqtt is enabled and started
ansible.builtin.systemd: ansible.builtin.systemd:
service: zigbee2mqtt service: zigbee2mqtt