64 lines
2.1 KiB
YAML
64 lines
2.1 KiB
YAML
---
|
|
# tasks file for Ansible-Docker-Compose-Role
|
|
- name: Check project limit
|
|
ansible.builtin.set_fact:
|
|
docker_compose_list_project_limit: "{{ docker_compose_project_limit | split(',') }}"
|
|
when: docker_compose_project_limit
|
|
|
|
- name: Get project_list
|
|
ansible.builtin.find:
|
|
paths:
|
|
- "{{ docker_compose_local_project_dir }}"
|
|
file_type: directory
|
|
register: docker_compose_find_results
|
|
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}] }}"
|
|
when: docker_compose_list_project_limit is undefined or item.path | basename in docker_compose_list_project_limit
|
|
loop: "{{ docker_compose_find_results.files }}"
|
|
|
|
- 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 }}"
|
|
register: docker_compose_out
|
|
changed_when: "'Started' in docker_compose_out.stderr"
|
|
|
|
- name: Prune docker
|
|
community.docker.docker_prune:
|
|
containers: true
|
|
images: true
|
|
images_filters:
|
|
dangling: false
|
|
networks: true
|
|
volumes: true
|
|
builder_cache: true
|