homeassistant/tasks/ensure_configuration.yml
2026-10-12 23:44:19 +02:00

31 lines
1.2 KiB
YAML

- name: Find Home Assistant configuration templates locally
ansible.builtin.set_fact:
ha_templates: "{{ query('ansible.builtin.fileglob', role_path + '/templates/homeassistant_configuration/*.yaml.j2') }}"
- name: Template Home Assistant configuration files
ansible.builtin.template:
src: "{{ item }}"
dest: "/srv/homeassistant/config/homeassistant/{{ item | basename | regex_replace('\\.j2$', '') }}"
mode: "0644"
loop: "{{ ha_templates }}"
loop_control:
label: "{{ item | basename }}"
- name: Ensure Home Assistant configuration.yaml exists
ansible.builtin.file:
path: "/srv/homeassistant/config/homeassistant/configuration.yaml"
state: touch
mode: "0644"
modification_time: preserve
access_time: preserve
- name: Add Home Assistant configuration includes
ansible.builtin.blockinfile:
path: "/srv/homeassistant/config/homeassistant/configuration.yaml"
marker: "# {mark} ANSIBLE MANAGED CONFIGURATION INCLUDES"
insertafter: EOF
block: |
{% for item in ha_templates | sort %}
{{ item | basename | regex_replace('\.yaml\.j2$', '') }}: !include {{ item | basename | regex_replace('\.j2$', '') }}
{% endfor %}