0
0
opnxng-deploy-playbook/deploy.yaml
2024-11-10 12:42:23 +08:00

66 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 /home/{{ ansible_user }}/Docker/{{ 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: "/home/{{ ansible_user }}/Docker/{{ 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: "/home/{{ ansible_user }}/Docker/{{ 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: "/home/{{ ansible_user }}/Docker/{{ 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 /home/{{ ansible_user }}/Docker/{{ 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 /home/{{ ansible_user }}/Docker/{{ item }}/docker-compose.yaml up --remove-orphans --force-recreate -d"
loop: "{{ compose[inventory_hostname] }}"
when: compose is defined and inventory_hostname in compose