docker/roles/docker_compose/tasks/main.yml

63 lines
2.1 KiB
YAML
Raw Normal View History

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"
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
# Compose V2 Not supported
# - name: Manage docker compose project
# community.docker.docker_compose:
# project_src: "{{ remote_project_dir + '/' + item.name }}"
# remove_orphans: true
# pull: true
# build: true
# state: "{{ docker_compose_state }}"
# loop: "{{ docker_compose_project_list }}"
- name: Manage docker compose project
ansible.builtin.shell:
chdir: "{{ docker_compose_remote_project_dir + '/' + item.name }}"
cmd: "docker compose pull && docker compose {{ 'restart' if docker_compose_state == 'restarted' else 'up -d' }} "
loop: "{{ docker_compose_project_list }}"
changed_when: "'Started' in docker_out.stderr"
- name: Prune docker
community.docker.docker_prune:
containers: true
images: true
images_filters:
dangling: false
networks: true
volumes: true
builder_cache: true