2022-12-08 23:45:22 +01:00
|
|
|
- name: Ensure acl is installed
|
2023-05-09 21:12:46 +02:00
|
|
|
become: true
|
2022-12-08 23:45:22 +01:00
|
|
|
ansible.builtin.apt:
|
|
|
|
name: acl
|
2023-05-09 14:39:50 +02:00
|
|
|
|
2022-12-08 23:45:22 +01:00
|
|
|
- name: Ensure git is installed
|
2023-05-09 21:12:46 +02:00
|
|
|
become: true
|
2022-12-08 23:45:22 +01:00
|
|
|
ansible.builtin.apt:
|
|
|
|
name: git
|
2023-05-09 14:39:50 +02:00
|
|
|
|
2022-12-08 23:45:22 +01:00
|
|
|
- name: Ensure zigbee2mqtt user exists
|
2023-05-09 21:12:46 +02:00
|
|
|
become: true
|
2022-12-08 23:45:22 +01:00
|
|
|
ansible.builtin.user:
|
|
|
|
name: zigbee2mqtt
|
|
|
|
groups:
|
|
|
|
- zigbee2mqtt
|
|
|
|
- dialout
|
|
|
|
group: zigbee2mqtt
|
2023-05-09 14:39:50 +02:00
|
|
|
|
|
|
|
- name: Ensure installation directory exists
|
2023-05-09 21:12:46 +02:00
|
|
|
become: true
|
2022-12-08 23:45:22 +01:00
|
|
|
ansible.builtin.file:
|
|
|
|
dest: /opt/zigbee2mqtt
|
|
|
|
state: directory
|
2023-05-09 14:39:50 +02:00
|
|
|
mode: "755"
|
2022-12-08 23:45:22 +01:00
|
|
|
owner: zigbee2mqtt
|
|
|
|
group: zigbee2mqtt
|
2023-05-09 14:39:50 +02:00
|
|
|
|
2022-12-08 23:45:22 +01:00
|
|
|
- name: Ensure zigbee2mqtt repository is cloned
|
2023-05-09 21:12:46 +02:00
|
|
|
become: true
|
2022-12-08 23:45:22 +01:00
|
|
|
become_user: zigbee2mqtt
|
|
|
|
ansible.builtin.git:
|
|
|
|
repo: https://github.com/Koenkk/zigbee2mqtt.git
|
|
|
|
depth: 1
|
|
|
|
dest: /opt/zigbee2mqtt
|
|
|
|
version: "{{ zigbee2mqtt__version }}"
|
|
|
|
notify: Restart zigbee2mqtt
|
2023-05-09 14:39:50 +02:00
|
|
|
|
2022-12-08 23:45:22 +01:00
|
|
|
- name: Ensure npm dependencies are installed
|
2023-05-09 21:12:46 +02:00
|
|
|
become: true
|
2022-12-08 23:45:22 +01:00
|
|
|
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
|
2023-05-09 14:39:50 +02:00
|
|
|
|
2022-12-08 23:45:22 +01:00
|
|
|
- name: Ensure custom zigbee2mqtt data directory exists
|
2023-05-09 21:12:46 +02:00
|
|
|
become: true
|
2022-12-08 23:45:22 +01:00
|
|
|
ansible.builtin.file:
|
|
|
|
dest: /home/zigbee2mqtt/zigbee2mqtt_data
|
|
|
|
state: directory
|
2023-05-09 14:39:50 +02:00
|
|
|
mode: "755"
|
2022-12-08 23:45:22 +01:00
|
|
|
owner: zigbee2mqtt
|
|
|
|
group: zigbee2mqtt
|
2023-05-09 14:39:50 +02:00
|
|
|
|
|
|
|
- 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
|
2023-05-09 21:12:46 +02:00
|
|
|
become: true
|
2023-05-09 14:39:50 +02:00
|
|
|
when: not zigbee2mqtt__conf_stat.stat.exists
|
2022-12-08 23:45:22 +01:00
|
|
|
ansible.builtin.copy:
|
2023-07-29 01:16:49 +02:00
|
|
|
content: "{{ zigbee2mqtt__initial_config }}"
|
2022-12-08 23:45:22 +01:00
|
|
|
dest: /home/zigbee2mqtt/zigbee2mqtt_data/configuration.yaml
|
2023-05-09 14:39:50 +02:00
|
|
|
mode: "640"
|
2022-12-08 23:45:22 +01:00
|
|
|
owner: zigbee2mqtt
|
|
|
|
group: zigbee2mqtt
|
|
|
|
notify: Restart zigbee2mqtt
|
2023-05-09 14:39:50 +02:00
|
|
|
|
2022-12-08 23:45:22 +01:00
|
|
|
- name: Ensure zigbee2mqtt service file is deployed
|
2023-05-09 21:12:46 +02:00
|
|
|
become: true
|
2022-12-08 23:45:22 +01:00
|
|
|
ansible.builtin.copy:
|
|
|
|
src: zigbee2mqtt.service
|
|
|
|
dest: /etc/systemd/system/zigbee2mqtt.service
|
2023-05-09 14:39:50 +02:00
|
|
|
mode: "644"
|
2022-12-08 23:45:22 +01:00
|
|
|
owner: root
|
|
|
|
group: root
|
|
|
|
notify: Reload systemd-daemon and restart zigbee2mqtt
|
2023-05-09 14:39:50 +02:00
|
|
|
|
2022-12-08 23:45:22 +01:00
|
|
|
- name: Ensure zigbee2mqtt is enabled and started
|
2023-05-09 21:12:46 +02:00
|
|
|
become: true
|
2022-12-08 23:45:22 +01:00
|
|
|
ansible.builtin.systemd:
|
|
|
|
service: zigbee2mqtt
|
|
|
|
enabled: true
|
|
|
|
state: started
|