0
0
opnxng-deploy-playbook/deploy.yaml
2024-06-06 23:52:16 +08:00

65 lines
2.3 KiB
YAML

---
- name: Docker Deploy
hosts: all
gather_facts: false
vars_files:
- vars/secrets.yaml
- vars/services.yaml
tasks:
# ----------------------------------------------------------------------------------------------------
- name: Docker Compose down
command: "docker-compose -f {{ docker_dir }}/{{ item }}/docker-compose.yaml down"
loop: "{{ down[inventory_hostname] }}"
when: down is defined and inventory_hostname in down
ignore_errors: yes
- name: Remove project directory
file:
path: "{{ docker_dir }}/{{ item }}"
state: absent
become: true
loop: "{{ remove[inventory_hostname] }}"
when: remove is defined and inventory_hostname in remove
ignore_errors: yes
# ----------------------------------------------------------------------------------------------------
- name: Create project directory
file:
path: "{{ docker_dir }}/{{ item }}"
state: directory
owner: 1000
group: 1000
mode: 0755
loop: "{{ compose[inventory_hostname] }}"
when: compose is defined and inventory_hostname in compose
- name: Inital configurations
include_tasks: "config-tasks/{{ item }}.yaml"
loop: "{{ config[inventory_hostname] }}"
when: config is defined and inventory_hostname in config
ignore_errors: yes
- name: Copy Docker Compose
template:
src: "compose/{{ item }}.yaml.j2"
dest: "{{ docker_dir }}/{{ item }}/docker-compose.yaml"
owner: 1000
group: 1000
mode: 0755
loop: "{{ compose[inventory_hostname] }}"
when: compose is defined and inventory_hostname in compose
# ----------------------------------------------------------------------------------------------------
- name: Docker Compose pull
command: "docker-compose -f {{ docker_dir }}/{{ item }}/docker-compose.yaml pull"
loop: "{{ compose[inventory_hostname] }}"
when: compose is defined and inventory_hostname in compose
- name: Docker Compose up
command: "docker-compose -f {{ docker_dir }}/{{ item }}/docker-compose.yaml up --remove-orphans --force-recreate -d"
loop: "{{ compose[inventory_hostname] }}"
when: compose is defined and inventory_hostname in compose