Allow to remove services via compose role
All checks were successful
continuous-integration/drone/push Build is passing
All checks were successful
continuous-integration/drone/push Build is passing
This commit is contained in:
parent
8d1a273b9a
commit
4dca002664
@ -98,6 +98,8 @@
|
|||||||
|
|
||||||
- name: Install Services
|
- name: Install Services
|
||||||
hosts: host.nc.chaoswg.org
|
hosts: host.nc.chaoswg.org
|
||||||
|
vars:
|
||||||
|
state: present
|
||||||
roles:
|
roles:
|
||||||
- { role: compose_project, service: traefik }
|
- { role: compose_project, service: traefik }
|
||||||
- { role: compose_project, service: keycloak }
|
- { role: compose_project, service: keycloak }
|
||||||
|
@ -2,3 +2,5 @@
|
|||||||
# defaults file for roles/compose_project
|
# defaults file for roles/compose_project
|
||||||
service: dummy
|
service: dummy
|
||||||
compose_dir: /home/core/compose
|
compose_dir: /home/core/compose
|
||||||
|
state: present # or absent
|
||||||
|
restart: smart # or always or never
|
||||||
|
67
coreos-config/roles/compose_project/tasks/create.yml
Normal file
67
coreos-config/roles/compose_project/tasks/create.yml
Normal file
@ -0,0 +1,67 @@
|
|||||||
|
---
|
||||||
|
|
||||||
|
- block:
|
||||||
|
- name: Create Temporary directory
|
||||||
|
tempfile:
|
||||||
|
state: directory
|
||||||
|
changed_when: false
|
||||||
|
register: temp_file
|
||||||
|
- name: Create directory structure
|
||||||
|
file:
|
||||||
|
state: directory
|
||||||
|
dest: '{{ temp_file.path }}/{{ item.path }}'
|
||||||
|
mode: "{{ item.mode }}"
|
||||||
|
changed_when: false
|
||||||
|
with_filetree: "./templates/{{ service | mandatory }}"
|
||||||
|
when: item.state == 'directory'
|
||||||
|
loop_control:
|
||||||
|
label: '{{ item.path }}'
|
||||||
|
- name: Template Service Files
|
||||||
|
ansible.builtin.template:
|
||||||
|
src: "{{ item.src }}"
|
||||||
|
dest: "{{ temp_file.path }}/{{ item.path }}"
|
||||||
|
mode: "{{ item.mode }}"
|
||||||
|
force: true
|
||||||
|
changed_when: false
|
||||||
|
with_filetree: "./templates/{{ service | mandatory }}"
|
||||||
|
loop_control:
|
||||||
|
label: '{{ item.path }}'
|
||||||
|
when: item.state == 'file'
|
||||||
|
delegate_to: localhost
|
||||||
|
check_mode: no
|
||||||
|
|
||||||
|
- name: Create Service Directory
|
||||||
|
file:
|
||||||
|
state: directory
|
||||||
|
path: "{{ compose_dir | mandatory }}"
|
||||||
|
|
||||||
|
- name: Copy Compose files
|
||||||
|
become: false
|
||||||
|
ansible.posix.synchronize:
|
||||||
|
src: "{{ temp_file.path | mandatory }}/"
|
||||||
|
dest: "{{ service_dir | mandatory }}"
|
||||||
|
archive: false
|
||||||
|
checksum: true
|
||||||
|
delete: true
|
||||||
|
recursive: true
|
||||||
|
mode: push
|
||||||
|
owner: false
|
||||||
|
group: false
|
||||||
|
perms: false
|
||||||
|
register: compose_files
|
||||||
|
|
||||||
|
- name: Delete temporary directory
|
||||||
|
ansible.builtin.file:
|
||||||
|
path: "{{ temp_file.path }}"
|
||||||
|
state: absent
|
||||||
|
changed_when: false
|
||||||
|
|
||||||
|
- name: Restart Service
|
||||||
|
community.docker.docker_compose:
|
||||||
|
project_src: "{{ service_dir | mandatory }}"
|
||||||
|
state: present
|
||||||
|
restarted: true
|
||||||
|
recreate: smart
|
||||||
|
build: true
|
||||||
|
remove_orphans: true
|
||||||
|
when: (compose_files.changed and restart == "smart") or restart == "always"
|
@ -9,68 +9,10 @@
|
|||||||
msg: "Working on {{ service }}"
|
msg: "Working on {{ service }}"
|
||||||
verbosity: 0
|
verbosity: 0
|
||||||
|
|
||||||
- block:
|
- include_tasks: create.yml
|
||||||
- name: Create Temporary directory
|
when: state == "present"
|
||||||
tempfile: state=directory
|
|
||||||
changed_when: false
|
|
||||||
register: temp_file
|
|
||||||
- name: Create directory structure
|
|
||||||
file:
|
|
||||||
state: directory
|
|
||||||
dest: '{{ temp_file.path }}/{{ item.path }}'
|
|
||||||
mode: "{{ item.mode }}"
|
|
||||||
changed_when: false
|
|
||||||
with_filetree: "./templates/{{ service | mandatory }}"
|
|
||||||
when: item.state == 'directory'
|
|
||||||
loop_control:
|
|
||||||
label: '{{ item.path }}'
|
|
||||||
- name: Template Service Files
|
|
||||||
ansible.builtin.template:
|
|
||||||
src: "{{ item.src }}"
|
|
||||||
dest: "{{ temp_file.path }}/{{ item.path }}"
|
|
||||||
mode: "{{ item.mode }}"
|
|
||||||
force: true
|
|
||||||
changed_when: false
|
|
||||||
with_filetree: "./templates/{{ service | mandatory }}"
|
|
||||||
loop_control:
|
|
||||||
label: '{{ item.path }}'
|
|
||||||
when: item.state == 'file'
|
|
||||||
delegate_to: localhost
|
|
||||||
check_mode: no
|
|
||||||
|
|
||||||
- name: Create Service Directory
|
- include_tasks: remove.yml
|
||||||
file:
|
when: state == "absent"
|
||||||
state: directory
|
|
||||||
path: "{{ compose_dir | mandatory }}"
|
|
||||||
|
|
||||||
- name: Copy Compose files
|
|
||||||
become: false
|
|
||||||
ansible.posix.synchronize:
|
|
||||||
src: "{{ temp_file.path | mandatory }}/"
|
|
||||||
dest: "{{ service_dir | mandatory }}"
|
|
||||||
archive: false
|
|
||||||
checksum: true
|
|
||||||
delete: true
|
|
||||||
recursive: true
|
|
||||||
mode: push
|
|
||||||
owner: false
|
|
||||||
group: false
|
|
||||||
perms: false
|
|
||||||
register: compose_files
|
|
||||||
|
|
||||||
- name: Delete temporary directory
|
|
||||||
ansible.builtin.file:
|
|
||||||
path: "{{ temp_file.path }}"
|
|
||||||
state: absent
|
|
||||||
changed_when: false
|
|
||||||
|
|
||||||
- name: Restart Service
|
|
||||||
community.docker.docker_compose:
|
|
||||||
project_src: "{{ service_dir | mandatory }}"
|
|
||||||
state: present
|
|
||||||
restarted: true
|
|
||||||
recreate: smart
|
|
||||||
build: true
|
|
||||||
remove_orphans: true
|
|
||||||
when: compose_files.changed
|
|
||||||
...
|
...
|
||||||
|
11
coreos-config/roles/compose_project/tasks/remove.yml
Normal file
11
coreos-config/roles/compose_project/tasks/remove.yml
Normal file
@ -0,0 +1,11 @@
|
|||||||
|
---
|
||||||
|
- name: Stop Service
|
||||||
|
community.docker.docker_compose:
|
||||||
|
project_src: "{{ service_dir | mandatory }}"
|
||||||
|
state: absent
|
||||||
|
remove_orphans: true
|
||||||
|
|
||||||
|
- name: Remove Service
|
||||||
|
file:
|
||||||
|
state: absent
|
||||||
|
path: "{{ service_dir | mandatory }}"
|
Loading…
Reference in New Issue
Block a user