xoxys.zigbee2mqtt/tasks/main.yml

59 lines
1.8 KiB
YAML
Raw Normal View History

2018-11-11 02:11:10 +00:00
---
2024-10-16 20:27:11 +00:00
- name: Create container volumes
community.docker.docker_volume:
name: "{{ item.name }}"
driver_options: "{{ item.options | default(omit) }}"
state: "{{ item.state | default('present') }}"
loop: "{{ zigbee2mqtt_volumes }}"
loop_control:
label: "{{ item.name }}"
when: item.type | default("volume") | lower == "volume"
register: __zigbee2mqtt_volumes_raw
- name: Register container volumes map
ansible.builtin.set_fact:
__zigbee2mqtt_volumes_map: "{{ __zigbee2mqtt_volumes_raw.results | json_query('[].volume') | items2dict(key_name='Name', value_name='Mountpoint') }}"
- name: Deploy env file
ansible.builtin.template:
src: etc/sysconfig/zigbee2mqtt.j2
dest: "/etc/sysconfig/zigbee2mqtt"
owner: root
group: root
mode: "0600"
notify: __zigbee2mqtt_restart
- name: Create container specs
ansible.builtin.template:
src: etc/systemd/system/zigbee2mqtt.service.j2
dest: "/etc/systemd/system/zigbee2mqtt.service"
owner: root
group: root
mode: "0640"
notify: __zigbee2mqtt_restart
- name: Deploy configuration file
2024-10-16 20:32:58 +00:00
ansible.builtin.template:
2024-10-16 20:27:11 +00:00
src: "zigbee2mqtt/configuration.yaml.j2"
dest: "{{ __zigbee2mqtt_volumes_map[zigbee2mqtt_data_volume] }}/configuration.yaml"
2024-10-16 20:32:58 +00:00
mode: "0600"
2024-10-16 20:27:11 +00:00
notify: __zigbee2mqtt_restart
- name: Ensure device files exists
2024-10-16 20:32:58 +00:00
ansible.builtin.file:
2024-10-16 20:27:11 +00:00
path: "{{ item }}"
2024-10-16 20:32:58 +00:00
mode: "0640"
2024-10-16 20:27:11 +00:00
state: touch
access_time: preserve
modification_time: preserve
loop:
- "{{ __zigbee2mqtt_volumes_map[zigbee2mqtt_data_volume] }}/devices.yaml"
- "{{ __zigbee2mqtt_volumes_map[zigbee2mqtt_data_volume] }}/groups.yaml"
- name: Ensure service state
ansible.builtin.service:
name: "zigbee2mqtt.service"
state: "{{ zigbee2mqtt_service_started | ternary('started', 'stopped', 'started') }}"
daemon_reload: True
enabled: True