58 lines
2.0 KiB
YAML
58 lines
2.0 KiB
YAML
# Use with: ansible-playbook -i inventories/inventory.proxmox.yml playbooks/dockerUpdate.yml --limit docker_hosts
|
|
- name: Update Docker containers
|
|
hosts: docker_hosts
|
|
become: true
|
|
vars:
|
|
docker_directories:
|
|
Plex:
|
|
- /home/jerick/plex
|
|
- /home/jerick/plexAutoLanguages
|
|
media-app:
|
|
- /home/jerick/audiobookshelf
|
|
- /home/jerick/authelia
|
|
- /home/jerick/bazarr
|
|
- /home/jerick/firefly3
|
|
- /home/jerick/gitea
|
|
- /home/jerick/gotify
|
|
- /home/jerick/it-tools
|
|
- /home/jerick/joplin
|
|
- /home/jerick/nginxproxy
|
|
- /home/jerick/ombi
|
|
- /home/jerick/picoshare
|
|
- /home/jerick/romM
|
|
- /home/jerick/tandoor_recipes
|
|
- /home/jerick/tautulli
|
|
- /home/jerick/watchtower
|
|
- /home/jerick/immich
|
|
media-management:
|
|
- /home/jerick/docker
|
|
tasks:
|
|
- name: Pull new images and update containers
|
|
community.docker.docker_compose_v2:
|
|
project_src: "{{ item }}"
|
|
state: present
|
|
loop: "{{ docker_directories[inventory_hostname] | default([]) }}"
|
|
when: inventory_hostname in docker_directories
|
|
|
|
- name: Prune Docker Images, Networks, etc
|
|
community.docker.docker_prune:
|
|
containers: true
|
|
images: true
|
|
networks: true
|
|
volumes: true
|
|
builder_cache: true
|
|
|
|
- name: Get status of all containers
|
|
ansible.builtin.command: "docker ps -a --format {{ '{{' }}.Names{{ '}}' }}|{{ '{{' }}.State{{ '}}' }}"
|
|
register: container_statuses
|
|
changed_when: false
|
|
|
|
- name: Identify containers not in running state
|
|
ansible.builtin.set_fact:
|
|
not_up_containers: "{{ container_statuses.stdout_lines | reject('search', '\\|running$') | map('split', '|') | map('first') | list }}"
|
|
|
|
- name: Report containers not in running state
|
|
ansible.builtin.debug:
|
|
msg: "WARNING: The following containers are not running on {{ inventory_hostname }}: {{ not_up_containers | join(', ') }}"
|
|
when: not_up_containers | length > 0
|