mirror of
https://github.com/kevinveenbirkenbach/computer-playbook.git
synced 2025-08-18 01:35:06 +02:00
Optimized reset routine for docker images and specially discourse
This commit is contained in:
parent
e3b09e7f1a
commit
03564b34bb
@ -2,8 +2,9 @@
|
||||
_dbtype: "{{ (database_type | d('') | trim) }}"
|
||||
_database_id: "{{ ('svc-db-' ~ _dbtype) if _dbtype else '' }}"
|
||||
_database_central_name: "{{ (applications | get_app_conf(_database_id, 'docker.services.' ~ _dbtype ~ '.name', False, '')) if _dbtype else '' }}"
|
||||
_database_consumer_entity_name: "{{ (database_application_id | d(application_id)) | get_entity_name }}"
|
||||
_database_central_enabled: "{{ (applications | get_app_conf(database_application_id, 'features.central_database', False)) if _dbtype else False }}"
|
||||
_database_consumer_id: "{{ database_application_id | d(application_id) }}"
|
||||
_database_consumer_entity_name: "{{ _database_consumer_id | get_entity_name }}"
|
||||
_database_central_enabled: "{{ (applications | get_app_conf(_database_consumer_id, 'features.central_database', False)) if _dbtype else False }}"
|
||||
|
||||
# Definition
|
||||
|
||||
@ -11,7 +12,7 @@ database_name: "{{ _database_consumer_entity_name }}"
|
||||
database_instance: "{{ _database_central_name if _database_central_enabled else database_name }}" # This could lead to bugs at dedicated database @todo cleanup
|
||||
database_host: "{{ _database_central_name if _database_central_enabled else 'database' }}" # This could lead to bugs at dedicated database @todo cleanup
|
||||
database_username: "{{ _database_consumer_entity_name }}"
|
||||
database_password: "{{ applications | get_app_conf(database_application_id, 'credentials.database_password', true) }}"
|
||||
database_password: "{{ applications | get_app_conf(_database_consumer_id, 'credentials.database_password', true) }}"
|
||||
database_port: "{{ (ports.localhost.database[_database_id] | d('')) if _dbtype else '' }}"
|
||||
database_env: "{{ docker_compose.directories.env }}{{ database_type }}.env"
|
||||
database_url_jdbc: "jdbc:{{ database_type if database_type == 'mariadb' else 'postgresql' }}://{{ database_host }}:{{ database_port }}/{{ database_name }}"
|
||||
|
@ -64,4 +64,3 @@
|
||||
applications: "{{ applications | append_csp_hash(application_id, matomo_tracking_code_one_liner) }}"
|
||||
no_log: "{{ MASK_CREDENTIALS_IN_LOGS | bool }}"
|
||||
changed_when: false
|
||||
|
||||
|
@ -6,14 +6,14 @@
|
||||
state: present
|
||||
notify: docker restart
|
||||
|
||||
- name: "Load cleanup tasks when MODE_CLEANUP or MODE_RESET is enabled"
|
||||
include_tasks: "03_cleanup.yml"
|
||||
when: MODE_CLEANUP | bool or MODE_RESET | bool
|
||||
|
||||
- name: "Load reset tasks when MODE_RESET is enabled"
|
||||
include_tasks: "02_reset.yml"
|
||||
when: MODE_RESET | bool
|
||||
|
||||
- name: "Load cleanup tasks when MODE_CLEANUP or MODE_RESET is enabled"
|
||||
include_tasks: "03_cleanup.yml"
|
||||
when: MODE_CLEANUP | bool or MODE_RESET | bool
|
||||
|
||||
- name: Include backup, repair and health services for docker
|
||||
include_role:
|
||||
name: "{{ item }}"
|
||||
|
@ -8,7 +8,6 @@
|
||||
name: "{{ (item.Names | default([item.Name]))[0] | regex_replace('^/','') }}"
|
||||
state: absent
|
||||
force_kill: true
|
||||
remove_volumes: false # NEVER SET TO TRUE - PREVENTS DELETION OF VOLUMES
|
||||
loop: "{{ docker_info.containers }}"
|
||||
loop_control:
|
||||
label: "{{ (item.Names | default([item.Name]))[0] }}"
|
||||
|
@ -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))
|
||||
|
@ -11,7 +11,7 @@ DISCOURSE_CONTAINER: "{{ applications | get_app_conf(application_id,
|
||||
DISCOURSE_NETWORK: "{{ applications | get_app_conf(application_id, 'docker.network') }}"
|
||||
DISCOURSE_VOLUME: "{{ applications | get_app_conf(application_id, 'docker.volumes.data') }}"
|
||||
DISCOURSE_PLUGINS: "{{ applications | get_app_conf(application_id, 'plugins') }}"
|
||||
DISCOURSE_PG_NETWORK: "{{ applications | get_app_conf('svc-db-postgres', 'docker.network' ) }}"
|
||||
DISCOURSE_PG_NETWORK: "{{ applications | get_app_conf('svc-db-' ~ database_type, 'docker.network' ) }}"
|
||||
DISCOURSE_REDIS_HOST: "{{ application_id | get_entity_name }}-redis"
|
||||
DISCOURSE_REPOSITORY_URL: "{{ applications | get_app_conf(application_id, 'docker.services.discourse.repository') }}"
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user