mirror of
https://github.com/kevinveenbirkenbach/computer-playbook.git
synced 2025-08-29 15:06:26 +02:00
Optimized reset routine for docker images and specially discourse
This commit is contained in:
@@ -1,14 +1,45 @@
|
||||
- name: "Load database variables for reset function"
|
||||
include_vars: "{{playbook_dir}}/roles/cmp-rdbms/vars/main.yml"
|
||||
# This reset function is redundant, because the 'sys-scv-docker' role reset will take care of it
|
||||
# anyhow lets keep this here for documentary purposes
|
||||
|
||||
- name: "cleanup central database from {{ application_id }}_default network"
|
||||
command:
|
||||
cmd: "docker network disconnect {{applications | get_app_conf(application_id, 'network', True)}} {{ database_host }}"
|
||||
ignore_errors: true
|
||||
- name: "Load database & docker-compose variables for reset"
|
||||
ansible.builtin.include_vars:
|
||||
file: "{{ item }}"
|
||||
loop:
|
||||
- "{{ playbook_dir }}/roles/docker-compose/vars/docker-compose.yml"
|
||||
- "{{ playbook_dir }}/roles/cmp-rdbms/vars/database.yml"
|
||||
|
||||
- name: "destroy container {{ DISCOURSE_CONTAINER }}"
|
||||
command:
|
||||
- name: Sanity check for required vars
|
||||
assert:
|
||||
that:
|
||||
- database_type is defined
|
||||
- applications is defined
|
||||
- docker_compose is defined
|
||||
- ports is defined
|
||||
fail_msg: "Load roles/docker-compose/vars/docker-compose.yml and set `database_type` first."
|
||||
|
||||
- name: "Disconnect DB container from Discourse networks"
|
||||
ansible.builtin.command:
|
||||
cmd: "docker network disconnect {{ discourse_network_item }} {{ database_host }}"
|
||||
loop:
|
||||
- "{{ DISCOURSE_NETWORK }}"
|
||||
- "{{ DISCOURSE_PG_NETWORK }}"
|
||||
loop_control:
|
||||
loop_var: discourse_network_item
|
||||
label: "{{ discourse_network_item }}"
|
||||
register: disc_net_disconnect
|
||||
changed_when: disc_net_disconnect.rc == 0
|
||||
failed_when: >
|
||||
disc_net_disconnect.rc != 0 and
|
||||
('is not connected' not in (disc_net_disconnect.stderr | default('') | lower)) and
|
||||
('no such network' not in (disc_net_disconnect.stderr | default('') | lower)) and
|
||||
('no such container' not in (disc_net_disconnect.stderr | default('') | lower))
|
||||
|
||||
- name: "destroy container '{{ DISCOURSE_CONTAINER }}'"
|
||||
ansible.builtin.command:
|
||||
cmd: "./launcher destroy {{ DISCOURSE_CONTAINER }}"
|
||||
chdir: "{{ DISCOURSE_REPOSITORY_DIR }}"
|
||||
ignore_errors: true
|
||||
notify: recreate discourse
|
||||
register: discourse_destroy
|
||||
changed_when: discourse_destroy.rc == 0
|
||||
failed_when: >
|
||||
discourse_destroy.rc != 0 and
|
||||
('unable to change directory before execution' not in (discourse_destroy.msg | default('') | lower))
|
||||
|
Reference in New Issue
Block a user