infrastructure/coreos-config/roles/compose_project/tasks/main.yml

77 lines
1.8 KiB
YAML
Raw Normal View History

2022-10-29 05:04:47 +02:00
---
- name: Set service_dir
ansible.builtin.set_fact:
service_dir: "{{ compose_dir | mandatory }}/{{ service | mandatory }}"
cacheable: true
- ansible.builtin.debug:
msg: "Working on {{ service }}"
verbosity: 0
- block:
- name: Create Temporary directory
tempfile: state=directory
changed_when: false
register: temp_file
- name: Create directory structure
file:
state: directory
dest: '{{ temp_file.path }}/{{ item.path }}'
mode: "{{ item.mode }}"
changed_when: false
with_filetree: "./templates/{{ service | mandatory }}"
when: item.state == 'directory'
loop_control:
label: '{{ item.path }}'
- name: Template Service Files
ansible.builtin.template:
src: "{{ item.src }}"
dest: "{{ temp_file.path }}/{{ item.path }}"
mode: "{{ item.mode }}"
force: true
changed_when: false
with_filetree: "./templates/{{ service | mandatory }}"
loop_control:
label: '{{ item.path }}'
when: item.state == 'file'
delegate_to: localhost
2022-10-29 17:06:15 +02:00
check_mode: no
2022-10-29 05:04:47 +02:00
- name: Create Service Directory
file:
state: directory
path: "{{ compose_dir | mandatory }}"
- name: Copy Compose files
become: false
ansible.posix.synchronize:
src: "{{ temp_file.path | mandatory }}/"
dest: "{{ service_dir | mandatory }}"
archive: false
checksum: true
delete: true
recursive: true
mode: push
owner: false
group: false
perms: false
register: compose_files
- name: Delete temporary directory
ansible.builtin.file:
path: "{{ temp_file.path }}"
state: absent
changed_when: false
- name: Restart Service
community.docker.docker_compose:
project_src: "{{ service_dir | mandatory }}"
state: present
restarted: true
recreate: smart
build: true
remove_orphans: true
when: compose_files.changed
...