add delete_all_tenants option to delete every tenants (#60811)

This commit is contained in:
Emmanuel Cazenave 2022-01-19 11:59:19 +01:00
parent 3424c598f6
commit da43ee2f28
3 changed files with 72 additions and 28 deletions

View File

@ -1,5 +1,5 @@
---
- name: delete all publik tenants
- name: delete publik tenants
hosts: local
vars:
venv_py3_bin: "{{venv_py3}}/bin"
@ -7,38 +7,59 @@
- facts
tasks:
- name: "delete hobo tenant"
command: "{{venv_py3_bin}}/{{apps['hobo']['project_name']}}-manage delete_tenant {{tenants_conf['dev-hobo']}}"
ignore_errors: yes
- name: "delete combo user tenant"
command: "{{venv_py3_bin}}/{{apps['combo']['project_name']}}-manage delete_tenant {{tenants_conf['user-combo']}}"
ignore_errors: yes
- import_tasks: tasks/delete_tenants.yml
vars:
app: hobo
tenant_dir: /var/lib/hobo/tenants
tenants: "{{[tenants_conf['dev-hobo']]}}"
delete_tenant_cmd: "{{venv_py3_bin}}/{{apps['hobo']['project_name']}}-manage delete_tenant"
- name: "delete combo agent tenant"
command: "{{venv_py3_bin}}/{{apps['combo']['project_name']}}-manage delete_tenant {{tenants_conf['agent-combo']}}"
ignore_errors: yes
- import_tasks: tasks/delete_tenants.yml
vars:
app: combo
tenant_dir: /var/lib/combo/tenants
tenants: "{{[tenants_conf['user-combo'], tenants_conf['agent-combo']]}}"
delete_tenant_cmd: "{{venv_py3_bin}}/{{apps['combo']['project_name']}}-manage delete_tenant"
- name: "delete authentic tenant"
command: "{{venv_py3_bin}}/{{apps['authentic']['project_name']}}-manage delete_tenant {{tenants_conf['connexion-authentic']}}"
ignore_errors: yes
- import_tasks: tasks/delete_tenants.yml
vars:
app: authentic
tenant_dir: /var/lib/authentic2-multitenant/tenants
tenants: "{{[tenants_conf['connexion-authentic']]}}"
delete_tenant_cmd: "{{venv_py3_bin}}/{{apps['authentic']['project_name']}}-manage delete_tenant"
- name: "delete wcs tenant"
command: "{{venv_py3_bin}}/wcsctl.py delete_tenant {{tenants_conf['demarches-wcs']}}"
ignore_errors: yes
- import_tasks: tasks/delete_tenants.yml
vars:
app: wcs
tenant_dir: /var/lib/wcs/tenants
tenants: "{{[tenants_conf['demarches-wcs']]}}"
delete_tenant_cmd: "{{venv_py3_bin}}/wcsctl.py delete_tenant"
- name: "delete fargo tenant"
command: "{{venv_py3_bin}}/{{apps['fargo']['project_name']}}-manage delete_tenant {{tenants_conf['dev-fargo']}}"
ignore_errors: yes
- import_tasks: tasks/delete_tenants.yml
vars:
app: fargo
tenant_dir: /var/lib/fargo/tenants
tenants: "{{[tenants_conf['dev-fargo']]}}"
delete_tenant_cmd: "{{venv_py3_bin}}/{{apps['fargo']['project_name']}}-manage delete_tenant"
- name: "delete chrono tenant"
command: "{{venv_py3_bin}}/{{apps['chrono']['project_name']}}-manage delete_tenant {{tenants_conf['dev-chrono']}}"
ignore_errors: yes
- import_tasks: tasks/delete_tenants.yml
vars:
app: chrono
tenant_dir: /var/lib/chrono/tenants
tenants: "{{[tenants_conf['dev-chrono']]}}"
delete_tenant_cmd: "{{venv_py3_bin}}/{{apps['chrono']['project_name']}}-manage delete_tenant"
- name: "delete passerelle tenant"
command: "{{venv_py3_bin}}/{{apps['passerelle']['project_name']}}-manage delete_tenant {{tenants_conf['dev-passerelle']}}"
ignore_errors: yes
- import_tasks: tasks/delete_tenants.yml
vars:
app: passerelle
tenant_dir: /var/lib/passerelle/tenants
tenants: "{{[tenants_conf['dev-passerelle']]}}"
delete_tenant_cmd: "{{venv_py3_bin}}/{{apps['passerelle']['project_name']}}-manage delete_tenant"
- name: "delete bijoe tenant"
command: "{{venv_py3_bin}}/{{apps['bijoe']['project_name']}}-manage delete_tenant {{tenants_conf['dev-bijoe']}}"
ignore_errors: yes
- import_tasks: tasks/delete_tenants.yml
vars:
app: bijoe
tenant_dir: /var/lib/bijoe/tenants
tenants: "{{[tenants_conf['dev-bijoe']]}}"
delete_tenant_cmd: "{{venv_py3_bin}}/{{apps['bijoe']['project_name']}}-manage delete_tenant"

View File

@ -1,6 +1,7 @@
clean_venv: false
compile_theme: true
django_version: 2.2.24
delete_all_tenants: true
git_ssh: false
devinst_share: /usr/local/share/publik-devinst
publik_conf: "/home/{{user}}/.config/publik"

22
tasks/delete_tenants.yml Normal file
View File

@ -0,0 +1,22 @@
- name: "Delete {{app}} main tenants"
command: "{{delete_tenant_cmd}} {{item}}"
ignore_errors: yes
loop: "{{tenants}}"
when: not delete_all_tenants
- name: "Find all {{app}} tenants"
ansible.builtin.find:
paths: "{{tenant_dir}}"
recurse: no
file_type: directory
use_regex: true
excludes: '.*\.invalid$'
register: all_tenants
when: delete_all_tenants
- name: "Delete all {{app}} tenants"
command: "{{delete_tenant_cmd}} {{item.path | basename}}"
loop: "{{all_tenants.files}}"
when: delete_all_tenants