Added: Update docker compose projects playbook

This commit is contained in:
Filip Rojek 2025-03-27 16:39:57 +01:00
parent 4c7e68c276
commit 7ee0bdba59
8 changed files with 95 additions and 22 deletions

2
group_vars/server.yaml Normal file
View File

@ -0,0 +1,2 @@
---
ansible_become_method: doas

View File

@ -0,0 +1,6 @@
---
ansible_connection: ssh
ansible_user: fr
ansible_host: 10.123.0.11
ansible_ssh_common_args: '-o StrictHostKeyChecking=no'
ansible_ssh_private_key_file: ~/.ssh/fr/fr-ansible@media.filiprojek.cz.ssh

6
host_vars/fofrweb-s3.yml Normal file
View File

@ -0,0 +1,6 @@
---
ansible_connection: ssh
ansible_user: filiprojek
ansible_host: 10.123.0.1
ansible_ssh_common_args: '-o StrictHostKeyChecking=no'
ansible_ssh_private_key_file: ~/.ssh/fofrweb/filiprojek@s3.fofrweb.com_2.ssh

3
host_vars/tests3.yaml Normal file
View File

@ -0,0 +1,3 @@
ansible_host: localhost
ansible_port: 2222
ansible_user: root

38
hosts
View File

@ -1,25 +1,19 @@
[server]
#10.123.0.1 # s3
#10.123.0.4 # rpi
#10.123.0.10 # microlab
#10.123.0.11 # media
#tests3
fofrweb-s3
filiprojek-media
10.123.0.1 # s3
10.123.0.4 # rpi
10.123.0.10 # microlab
10.123.0.11 # media
[server:vars]
ansible_user=ansible
ansible_ssh_private_key_file=~/.ssh/fofrweb/ansible@fofrweb.com.ssh
ansible_become_method=doas
[pc]
10.123.0.100 # x230
10.123.0.102 # filip-laptop
10.123.0.103 # t480
[pc:vars]
ansible_user=fr
# ansible_ssh_private_key_file=~/.ssh/fofrweb/ansible@fofrweb.com.ssh
ansible_become_method=doas
#[pc]
#10.123.0.100 # x230
#10.123.0.102 # filip-laptop
#10.123.0.103 # t480
#
#[pc:vars]
#ansible_user=fr
## ansible_ssh_private_key_file=~/.ssh/fofrweb/ansible@fofrweb.com.ssh
#ansible_become_method=doas

View File

@ -8,3 +8,9 @@
name: bash,vim,htop,neofetch
state: latest
- name: install docker
become: true
apk:
name: docker
state: present

View File

@ -0,0 +1,23 @@
---
- name: Pull updated images for project at {{ project.path }}
community.docker.docker_compose_v2_pull:
project_src: "{{ project.path }}"
register: pull_result
- name: Debug pull result for {{ project.path }}
debug:
msg: "Pull changed: {{ pull_result.changed }} for project at {{ project.path }}"
- name: Restart project at {{ project.path }} if images updated
block:
- name: Bring project down at {{ project.path }}
community.docker.docker_compose_v2:
project_src: "{{ project.path }}"
state: absent
- name: Bring project up (detached) at {{ project.path }}
community.docker.docker_compose_v2:
project_src: "{{ project.path }}"
state: present
when: pull_result.changed

View File

@ -0,0 +1,33 @@
---
- name: Update docker-compose projects on filiprojek-media
hosts: filiprojek-media
become: false # user fr is in the docker group
vars:
docker_projects:
- path: /srv/docker/immich/
- path: /srv/docker/jellyfin/
- path: /srv/docker/radarr/
- path: /srv/docker/syncthing/
tasks:
- name: Process each docker-compose project
ansible.builtin.include_tasks: update-docker-project.yaml
loop: "{{ docker_projects }}"
loop_control:
loop_var: project
- name: Update docker-compose projects fofrweb-s3
hosts: fofrweb-s3
become: false # user filiprojek is in the docker group
vars:
docker_projects:
- path: /srv/www/cz/filiprojek/git
- path: /srv/www/com/fofrweb/status
tasks:
- name: Process each docker-compose project
ansible.builtin.include_tasks: update-docker-project.yaml
loop: "{{ docker_projects }}"
loop_control:
loop_var: project