/
/
/
Ansible role that deploys a supervised home assistant installation on my homeassistant device.
1---
2# Home Assistant Services - Pull latest images and recreate containers
3#
4# Covers the containers this role deploys itself. Home Assistant core and
5# its add-ons are updated by the Supervisor, not here.
6#
7# Usage via update-services.yml:
8# All services: ansible-playbook update-services.yml --limit homeassistant_servers
9# Reverse proxy only: ansible-playbook update-services.yml --limit homeassistant_servers --tags npm
10# Semaphore only: ansible-playbook update-services.yml --limit homeassistant_servers --tags semaphore
11
12# NPM and CrowdSec share one compose project, so they update together.
13# Every proxied service briefly drops while NPM is recreated.
14- name: Update Reverse Proxy (NPM + CrowdSec)
15 when: homeassistant_npm_enabled | bool
16 tags: [npm, reverse-proxy, crowdsec]
17 block:
18 - name: "Reverse Proxy - Pull latest images and recreate"
19 community.docker.docker_compose_v2:
20 project_src: "{{ homeassistant_docker_base_path }}/reverse-proxy"
21 state: present
22 pull: always
23 recreate: auto
24 register: reverse_proxy_update
25
26 - name: "Reverse Proxy - Report update status"
27 ansible.builtin.debug:
28 msg: "Reverse Proxy: {{ 'updated and recreated' if reverse_proxy_update.changed else 'already up to date' }}"
29
30- name: Update Semaphore
31 when: homeassistant_semaphore_enabled | bool
32 tags: [semaphore]
33 block:
34 - name: "Semaphore - Pull latest image and recreate"
35 community.docker.docker_compose_v2:
36 project_src: "{{ homeassistant_semaphore_dir }}"
37 state: present
38 pull: always
39 recreate: auto
40 register: semaphore_update
41
42 - name: "Semaphore - Report update status"
43 ansible.builtin.debug:
44 msg: "Semaphore: {{ 'updated and recreated' if semaphore_update.changed else 'already up to date' }}"
45
46# Dangling only: the Supervisor keeps its own images for rollback, and those
47# are tagged, so this never touches them.
48- name: Prune unused Docker images
49 tags: [cleanup, prune]
50 community.docker.docker_prune:
51 images: true
52 images_filters:
53 dangling: "true"
54 register: prune_result
55
56- name: Report cleanup
57 tags: [cleanup, prune]
58 ansible.builtin.debug:
59 msg: "Pruned {{ prune_result.images | default([]) | length }} dangling image(s), reclaimed {{ prune_result.images_space_reclaimed | default(0) | human_readable }}"
60 when: prune_result.images | default([]) | length > 0
61