Reload config when needed using ansible

For any ansible users out there I want to share how I reload config when needed without having to use the UI or restart.

So for instance I have a task that configures my group config:

- name: "Deploy home assistant group templates"
  become: yes
  template:
    src: "{{ item.name }}.j2"
    dest: "/home/{{ home_assistant_user }}/.homeassistant/{{ item.name }}"
    owner: "{{ home_assistant_user }}"
    group: "{{ home_assistant_user }}"
    block_start_string: "{{ item.block_start | default('{%') }}"
    block_end_string: "{{ item.block_end | default('%}') }}"
    variable_start_string: "{{ item.variable_start | default('{{') }}"
    variable_end_string: "{{ item.variable_end | default('}}') }}"
  with_items:
    - { 'name': 'group/home.yaml' }
    - { 'name': 'group/topfloor.yaml' }
    - { 'name': 'group/mainfloor.yaml' }
    - { 'name': 'group/basement.yaml' }
  tags: hass_deploy_cfg
  notify: Reload group config

And my notify handler looks like this:

- name: Reload group config
  uri:
    url: https://example.com/api/services/group/reload
    method: POST
    headers:
      x-ha-access: "{{ hass_password }}"
      Content-Type: application/json
2 Likes