2023-06-29 14:02:54 +02:00
|
|
|
---
|
|
|
|
# tasks file for Ansible-Docker-Compose-Role
|
|
|
|
- name: Check project limit
|
|
|
|
ansible.builtin.set_fact:
|
2023-06-29 14:07:01 +02:00
|
|
|
docker_compose_list_project_limit: "{{ docker_compose_project_limit | split(',') }}"
|
2023-06-29 14:02:54 +02:00
|
|
|
when: docker_compose_project_limit
|
|
|
|
|
|
|
|
- name: Get project_list
|
|
|
|
ansible.builtin.find:
|
|
|
|
paths:
|
|
|
|
- "{{ docker_compose_local_project_dir }}"
|
|
|
|
file_type: directory
|
2023-06-29 14:07:01 +02:00
|
|
|
register: docker_compose_find_results
|
2023-06-29 14:02:54 +02:00
|
|
|
delegate_to: localhost
|
|
|
|
|
|
|
|
- name: Arrange et filter folder list
|
|
|
|
ansible.builtin.set_fact:
|
|
|
|
docker_compose_project_list: "{{ docker_compose_project_list + [{'path': item.path, 'name': item.path | basename}] }}"
|
2023-06-29 14:07:01 +02:00
|
|
|
when: docker_compose_list_project_limit is undefined or item.path | basename in docker_compose_list_project_limit
|
|
|
|
loop: "{{ docker_compose_find_results.files }}"
|
2023-06-29 14:02:54 +02:00
|
|
|
|
|
|
|
- name: Copy projects
|
|
|
|
ansible.builtin.copy:
|
|
|
|
src: "{{ item.path }}"
|
|
|
|
dest: "{{ docker_compose_remote_project_dir }}"
|
|
|
|
mode: "preserve"
|
|
|
|
directory_mode: "711"
|
2024-04-20 13:40:35 +02:00
|
|
|
register: copy_result
|
2023-06-29 14:02:54 +02:00
|
|
|
loop: "{{ docker_compose_project_list }}"
|
|
|
|
|
|
|
|
- name: Create external docker networks
|
|
|
|
community.docker.docker_network:
|
|
|
|
name: "{{ item.name }}"
|
|
|
|
state: "{{ item.state | default('present') }}"
|
|
|
|
loop: "{{ docker_compose_external_network }}"
|
|
|
|
when: docker_compose_external_network is defined
|
|
|
|
|
|
|
|
- name: Manage docker compose project
|
2024-04-20 13:40:35 +02:00
|
|
|
community.docker.docker_compose_v2:
|
|
|
|
project_src: "{{ docker_compose_remote_project_dir + '/' + item.item.name }}"
|
|
|
|
remove_orphans: true
|
|
|
|
pull: always
|
|
|
|
build: always
|
2024-04-30 11:10:28 +02:00
|
|
|
state: "{{ docker_compose_state }}"
|
2024-04-20 13:40:35 +02:00
|
|
|
loop: "{{ copy_result.results }}"
|
|
|
|
when: not item.failed
|
2024-04-20 13:53:39 +02:00
|
|
|
register: result
|
|
|
|
changed_when: "'Started' in result.stderr"
|
2024-04-20 13:40:35 +02:00
|
|
|
|
2024-04-30 11:10:28 +02:00
|
|
|
# - name: Force restart
|
|
|
|
# community.docker.docker_compose_v2:
|
|
|
|
# project_src: "{{ docker_compose_remote_project_dir + '/' + item.item.item.name }}"
|
|
|
|
# remove_orphans: true
|
|
|
|
# pull: always
|
|
|
|
# build: always
|
|
|
|
# state: "restarted"
|
|
|
|
# loop: "{{ result.results }}"
|
|
|
|
# when: not item.changed and (copy_result.results | selectattr('item.name', 'eq', item.item.item.name) | map(attribute='changed'))
|
2023-06-29 14:02:54 +02:00
|
|
|
|
|
|
|
- name: Prune docker
|
|
|
|
community.docker.docker_prune:
|
|
|
|
containers: true
|
|
|
|
images: true
|
|
|
|
images_filters:
|
|
|
|
dangling: false
|
|
|
|
networks: true
|
|
|
|
volumes: true
|
|
|
|
builder_cache: true
|