0
0
opnxng-deploy-playbook/deploy.yaml

65 lines
2.3 KiB
YAML
Raw Normal View History

2023-11-06 10:39:27 +08:00
---
- name: Docker Deploy
hosts: all
gather_facts: false
vars_files:
2023-11-13 20:27:07 +08:00
- vars/secrets.yaml
- vars/services.yaml
2023-11-06 10:39:27 +08:00
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
2023-11-11 21:29:49 +08:00
- name: Inital configurations
2023-11-13 20:27:07 +08:00
include_tasks: "config-tasks/{{ item }}.yaml"
2023-11-11 21:29:49 +08:00
loop: "{{ config[inventory_hostname] }}"
when: config is defined and inventory_hostname in config
2023-11-06 10:39:27 +08:00
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