ansible/privfrontends/docker-tasks.yaml
2023-07-07 22:40:54 +05:30

54 lines
1.3 KiB
YAML

---
- name: Create directory for service
ansible.builtin.file:
path: /opt/docker/{{ item }}
state: directory
mode: "0755"
tags: docker
- name: Copy docker-compose templates for the service
ansible.builtin.template:
src: ./compose/{{ item }}/compose.yml.j2
dest: /opt/docker/{{ item }}/compose.yml
backup: true
mode: preserve
register: check_status
tags: docker
- name: Check if extras file exists for the service
delegate_to: localhost
ansible.builtin.stat:
path: ./compose/{{ item }}/extras.conf.j2
register: file
tags: docker
- name: Copy extras file
ansible.builtin.template:
src: ./compose/{{ item }}/extras.conf.j2
dest: /opt/docker/{{ item }}/extras.conf
backup: true
mode: preserve
when: file.stat.exists
tags: docker
- name: "Update docker service image"
ansible.builtin.command:
chdir: "/opt/docker/{{ item }}"
cmd: docker compose pull
when: check_status.changed
tags: docker
- name: "Stop docker service"
ansible.builtin.command:
chdir: "/opt/docker/{{ item }}"
cmd: docker compose down
when: check_status.changed
tags: docker
- name: "Start docker service"
ansible.builtin.command:
chdir: "/opt/docker/{{ item }}"
cmd: docker compose up -d --build --remove-orphans
when: check_status.changed
tags: docker