Update dockers playbook converted into role
This commit is contained in:
		
							
								
								
									
										11
									
								
								README.md
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										11
									
								
								README.md
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,11 @@
 | 
				
			|||||||
 | 
					# Ansible FR
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					## Ping server group
 | 
				
			||||||
 | 
					```sh
 | 
				
			||||||
 | 
					ansible -m ping server
 | 
				
			||||||
 | 
					```
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					## Update docker composes on my servers
 | 
				
			||||||
 | 
					```sh
 | 
				
			||||||
 | 
					ansible-playbook playbooks/update_dockers.yaml
 | 
				
			||||||
 | 
					```
 | 
				
			||||||
@@ -4,3 +4,4 @@ remote_user = root
 | 
				
			|||||||
forks = 8
 | 
					forks = 8
 | 
				
			||||||
interpreter_python = /usr/bin/python3
 | 
					interpreter_python = /usr/bin/python3
 | 
				
			||||||
nocows=1
 | 
					nocows=1
 | 
				
			||||||
 | 
					roles_path = ./roles:./playbooks/roles
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -1,23 +0,0 @@
 | 
				
			|||||||
---
 | 
					 | 
				
			||||||
- 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
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
@@ -3,31 +3,20 @@
 | 
				
			|||||||
  hosts: filiprojek-media
 | 
					  hosts: filiprojek-media
 | 
				
			||||||
  become: false # user fr is in the docker group
 | 
					  become: false # user fr is in the docker group
 | 
				
			||||||
  vars:
 | 
					  vars:
 | 
				
			||||||
    docker_projects:
 | 
					    docker_composes:
 | 
				
			||||||
      - path: /srv/docker/immich/
 | 
					      - path: /srv/docker/immich/
 | 
				
			||||||
      - path: /srv/docker/jellyfin/
 | 
					      - path: /srv/docker/jellyfin/
 | 
				
			||||||
      - path: /srv/docker/radarr/
 | 
					      - path: /srv/docker/radarr/
 | 
				
			||||||
      - path: /srv/docker/syncthing/
 | 
					      - path: /srv/docker/syncthing/
 | 
				
			||||||
      
 | 
					  roles:
 | 
				
			||||||
  tasks:
 | 
					    - update_docker
 | 
				
			||||||
    - 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
 | 
					- name: Update docker-compose projects fofrweb-s3
 | 
				
			||||||
  hosts: fofrweb-s3
 | 
					  hosts: fofrweb-s3
 | 
				
			||||||
  become: false # user filiprojek is in the docker group
 | 
					  become: false # user filiprojek is in the docker group
 | 
				
			||||||
  vars:
 | 
					  vars:
 | 
				
			||||||
    docker_projects:
 | 
					    docker_composes:
 | 
				
			||||||
      - path: /srv/www/cz/filiprojek/git
 | 
					      - path: /srv/www/cz/filiprojek/git
 | 
				
			||||||
      - path: /srv/www/com/fofrweb/status
 | 
					      - path: /srv/www/com/fofrweb/status
 | 
				
			||||||
      
 | 
					  roles:
 | 
				
			||||||
  tasks:
 | 
					    - update_docker
 | 
				
			||||||
    - name: Process each docker-compose project
 | 
					 | 
				
			||||||
      ansible.builtin.include_tasks: update-docker-project.yaml
 | 
					 | 
				
			||||||
      loop: "{{ docker_projects }}"
 | 
					 | 
				
			||||||
      loop_control:
 | 
					 | 
				
			||||||
        loop_var: project
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
 
 | 
				
			|||||||
							
								
								
									
										7
									
								
								roles/update_docker/tasks/main.yaml
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										7
									
								
								roles/update_docker/tasks/main.yaml
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,7 @@
 | 
				
			|||||||
 | 
					---
 | 
				
			||||||
 | 
					- name: Process each docker-compose project
 | 
				
			||||||
 | 
					  ansible.builtin.include_tasks: update_compose.yaml
 | 
				
			||||||
 | 
					  loop: "{{ docker_composes }}"
 | 
				
			||||||
 | 
					  loop_control:
 | 
				
			||||||
 | 
					    loop_var: compose
 | 
				
			||||||
 | 
					
 | 
				
			||||||
							
								
								
									
										24
									
								
								roles/update_docker/tasks/update_compose.yaml
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										24
									
								
								roles/update_docker/tasks/update_compose.yaml
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,24 @@
 | 
				
			|||||||
 | 
					---
 | 
				
			||||||
 | 
					- name: Pull updated images for compose at {{ compose.path }}
 | 
				
			||||||
 | 
					  community.docker.docker_compose_v2_pull:
 | 
				
			||||||
 | 
					    project_src: "{{ compose.path }}"
 | 
				
			||||||
 | 
					  register: pull_result
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					#- name: Debug pull result for {{ compose.path }}
 | 
				
			||||||
 | 
					#  debug:
 | 
				
			||||||
 | 
					#    msg: "Pull changed: {{ pull_result.changed }} for compose at {{ compose.path }}"
 | 
				
			||||||
 | 
					#  when: pull_result.changed
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					- name: Restart compose at {{ compose.path }} if images updated
 | 
				
			||||||
 | 
					  block:
 | 
				
			||||||
 | 
					    - name: Bring compose down at {{ compose.path }}
 | 
				
			||||||
 | 
					      community.docker.docker_compose_v2:
 | 
				
			||||||
 | 
					        project_src: "{{ compose.path }}"
 | 
				
			||||||
 | 
					        state: absent
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    - name: Bring compose up (detached) at {{ compose.path }}
 | 
				
			||||||
 | 
					      community.docker.docker_compose_v2:
 | 
				
			||||||
 | 
					        project_src: "{{ compose.path }}"
 | 
				
			||||||
 | 
					        state: present
 | 
				
			||||||
 | 
					  when: pull_result.changed
 | 
				
			||||||
 | 
					
 | 
				
			||||||
		Reference in New Issue
	
	Block a user