0
0
opnxng-deploy-playbook/deploy.yaml

66 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:
2024-11-02 18:19:03 +08:00
2023-11-06 10:39:27 +08:00
# ----------------------------------------------------------------------------------------------------
- name: Docker Compose down
2024-11-02 18:19:03 +08:00
command: "docker-compose -f /home/{{ ansible_user }}/Docker/{{ item }}/docker-compose.yaml down"
2023-11-06 10:39:27 +08:00
loop: "{{ down[inventory_hostname] }}"
when: down is defined and inventory_hostname in down
ignore_errors: yes
- name: Remove project directory
file:
2024-11-02 18:19:03 +08:00
path: "/home/{{ ansible_user }}/Docker/{{ item }}"
2023-11-06 10:39:27 +08:00
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:
2024-11-02 18:19:03 +08:00
path: "/home/{{ ansible_user }}/Docker/{{ item }}"
2023-11-06 10:39:27 +08:00
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"
2024-11-02 18:19:03 +08:00
dest: "/home/{{ ansible_user }}/Docker/{{ item }}/docker-compose.yaml"
2023-11-06 10:39:27 +08:00
owner: 1000
group: 1000
mode: 0755
loop: "{{ compose[inventory_hostname] }}"
when: compose is defined and inventory_hostname in compose
# ----------------------------------------------------------------------------------------------------
- name: Docker Compose pull
2024-11-02 18:19:03 +08:00
command: "docker-compose -f /home/{{ ansible_user }}/Docker/{{ item }}/docker-compose.yaml pull"
2023-11-06 10:39:27 +08:00
loop: "{{ compose[inventory_hostname] }}"
when: compose is defined and inventory_hostname in compose
- name: Docker Compose up
2024-11-02 18:19:03 +08:00
command: "docker-compose -f /home/{{ ansible_user }}/Docker/{{ item }}/docker-compose.yaml up --remove-orphans --force-recreate -d"
2023-11-06 10:39:27 +08:00
loop: "{{ compose[inventory_hostname] }}"
2024-11-02 18:19:03 +08:00
when: compose is defined and inventory_hostname in compose