Michael Grote
7c0c860600
Reviewed-on: #601 Co-authored-by: Michael Grote <michael.grote@posteo.de> Co-committed-by: Michael Grote <michael.grote@posteo.de>
93 lines
3 KiB
YAML
93 lines
3 KiB
YAML
---
|
|
- name: ensure basedir exists
|
|
become: true
|
|
ansible.builtin.file:
|
|
path: "{{ compose_dest_basedir }}"
|
|
state: directory
|
|
mode: "{{ compose_dir_permissions }}"
|
|
owner: "{{ compose_owner }}"
|
|
group: "{{ compose_group }}"
|
|
|
|
# https://codeutility.org/ansible-can-the-templates-module-handle-multiple-templates-directories-stack-overflow/
|
|
- name: ensure all directories exists
|
|
ansible.builtin.file:
|
|
dest: "{{ compose_dest_basedir }}/{{ item | replace(compose_src_basedir + '/', '') }}"
|
|
state: directory
|
|
mode: "{{ compose_dir_permissions }}"
|
|
owner: "{{ compose_owner }}"
|
|
group: "{{ compose_group }}"
|
|
with_items: "{{ lookup('pipe', 'find '+ compose_src_basedir +'/ -type d').split('\n') }}"
|
|
|
|
- name: ensure all files exists (can take a long time)
|
|
ansible.builtin.copy:
|
|
mode: "{{ compose_file_permissions }}"
|
|
owner: "{{ compose_owner }}"
|
|
group: "{{ compose_group }}"
|
|
src: "{{ item }}"
|
|
dest: "{{ compose_dest_basedir }}/{{ item | replace(compose_src_basedir + '/', '') }}"
|
|
with_items: "{{ lookup('pipe', 'find '+ compose_src_basedir +'/ -type f -not -name *.j2 ').split('\n') }}"
|
|
no_log: true
|
|
|
|
- name: ensure templated files exists
|
|
ansible.builtin.template:
|
|
mode: "{{ compose_file_permissions }}"
|
|
owner: "{{ compose_owner }}"
|
|
group: "{{ compose_group }}"
|
|
src: "{{ item }}"
|
|
dest: "{{ compose_dest_basedir }}/{{ item | replace(compose_src_basedir + '/', '') | replace('.j2', '') }}"
|
|
with_items: "{{ lookup('pipe', 'find '+ compose_src_basedir +'/ -type f -name *.j2').split('\n') }}"
|
|
no_log: true
|
|
register: copy_template
|
|
|
|
- name: Ensure needed networks exists
|
|
become: true
|
|
community.docker.docker_network:
|
|
name: "{{ item.network }}"
|
|
state: present
|
|
internal: false
|
|
enable_ipv6: false
|
|
driver: bridge
|
|
loop: "{{ compose_files }}"
|
|
when:
|
|
- item.network is defined
|
|
|
|
- name: (re)start container
|
|
become: true
|
|
ansible.builtin.command: docker-compose up -d
|
|
args:
|
|
chdir: "{{ compose_dest_basedir }}/{{ item.name }}"
|
|
register: start_result # speichere ergebnis in var
|
|
changed_when: "start_result.rc == 0" # markiere tasks als changed when exit-code == 0
|
|
loop: "{{ compose_files }}"
|
|
when:
|
|
- item.state == "present"
|
|
- copy_template is changed
|
|
|
|
- name: stop old container
|
|
become: true
|
|
ansible.builtin.command: docker-compose down # noqa no-changed-when
|
|
args:
|
|
chdir: "{{ compose_dest_basedir }}/{{ item.name }}"
|
|
loop: "{{ compose_files }}"
|
|
when:
|
|
- item.state == "absent"
|
|
ignore_errors: true # noqa ignore-errors
|
|
|
|
- name: Ensure old networks are absent
|
|
become: true
|
|
community.docker.docker_network:
|
|
name: "{{ item.network }}"
|
|
state: absent
|
|
loop: "{{ compose_files }}"
|
|
when:
|
|
- item.network is defined
|
|
- item.state == "absent"
|
|
|
|
- name: remove old docker-compose files & directories
|
|
become: true
|
|
ansible.builtin.file:
|
|
path: "{{ compose_dest_basedir }}/{{ item.name }}/"
|
|
state: absent
|
|
loop: "{{ compose_files }}"
|
|
when:
|
|
- item.state == "absent"
|