matrix-docker-ansible-deploy/roles/matrix-awx/tasks/purge_media_main.yml

112 lines
3.7 KiB
YAML
Raw Normal View History

---
2021-08-13 08:05:57 +00:00
- name: Ensure dateutils is installed in AWX
2021-08-13 08:05:57 +00:00
delegate_to: 127.0.0.1
yum:
name: dateutils
state: latest
- name: Include vars in matrix_vars.yml
include_vars:
file: '/var/lib/awx/projects/clients/{{ member_id }}/{{ subscription_id }}/matrix_vars.yml'
no_log: true
2021-11-15 20:43:05 +00:00
2021-08-13 08:05:57 +00:00
- name: Ensure curl and jq intalled on target machine
apt:
pkg:
- curl
- jq
2021-08-13 08:05:57 +00:00
state: present
- name: Collect the internal IP of the matrix-synapse container
shell: "/usr/bin/docker inspect --format '{''{range.NetworkSettings.Networks}''}{''{.IPAddress}''}{''{end}''}' matrix-synapse"
2021-10-10 05:23:49 +00:00
register: awx_synapse_container_ip
2021-08-13 08:05:57 +00:00
2021-12-06 03:54:31 +00:00
- name: Collect access token for @admin-janitor user
2021-08-13 08:05:57 +00:00
shell: |
2021-12-06 03:54:31 +00:00
curl -XPOST -d '{"type":"m.login.password", "user":"admin-janitor", "password":"{{ awx_janitor_user_password }}"}' "{{ awx_synapse_container_ip.stdout }}:{{ matrix_synapse_container_client_api_port }}/_matrix/client/r0/login" | jq '.access_token'
2021-10-10 05:23:49 +00:00
register: awx_janitors_token
no_log: true
2021-08-13 08:05:57 +00:00
- name: Generate list of dates to purge to
delegate_to: 127.0.0.1
2021-11-24 02:43:25 +00:00
shell: "dateseq {{ awx_purge_from_date }} {{ awx_purge_to_date }}"
2021-10-10 05:23:49 +00:00
register: awx_purge_dates
2021-11-15 20:43:05 +00:00
2021-08-13 08:05:57 +00:00
- name: Calculate initial size of local media repository
shell: du -sh /matrix/synapse/storage/media-store/local*
2021-10-10 05:23:49 +00:00
register: awx_local_media_size_before
when: awx_purge_media_type == "Local Media"
2021-11-24 02:43:25 +00:00
async: 600
ignore_errors: true
no_log: true
2021-08-13 08:05:57 +00:00
- name: Calculate initial size of remote media repository
shell: du -sh /matrix/synapse/storage/media-store/remote*
2021-10-10 05:23:49 +00:00
register: awx_remote_media_size_before
when: awx_purge_media_type == "Remote Media"
async: 600
ignore_errors: true
no_log: true
2021-08-13 08:05:57 +00:00
- name: Purge local media with loop
2021-11-15 20:43:05 +00:00
include_tasks: purge_media_local.yml
2021-10-10 05:23:49 +00:00
loop: "{{ awx_purge_dates.stdout_lines | flatten(levels=1) }}"
when: awx_purge_media_type == "Local Media"
2021-08-13 08:05:57 +00:00
- name: Purge remote media with loop
2021-11-15 20:43:05 +00:00
include_tasks: purge_media_remote.yml
2021-10-10 05:23:49 +00:00
loop: "{{ awx_purge_dates.stdout_lines | flatten(levels=1) }}"
when: awx_purge_media_type == "Remote Media"
2021-08-13 08:05:57 +00:00
- name: Calculate final size of local media repository
shell: du -sh /matrix/synapse/storage/media-store/local*
2021-10-10 05:23:49 +00:00
register: awx_local_media_size_after
when: awx_purge_media_type == "Local Media"
ignore_errors: true
no_log: true
2021-08-13 08:05:57 +00:00
- name: Calculate final size of remote media repository
shell: du -sh /matrix/synapse/storage/media-store/remote*
2021-10-10 05:23:49 +00:00
register: awx_remote_media_size_after
when: awx_purge_media_type == "Remote Media"
ignore_errors: true
no_log: true
2021-08-13 08:05:57 +00:00
- name: Print size of local media repository before purge
debug:
2021-10-10 05:23:49 +00:00
msg: "{{ awx_local_media_size_before.stdout.split('\n') }}"
when: awx_purge_media_type == "Local Media"
2021-08-13 08:05:57 +00:00
- name: Print size of local media repository after purge
debug:
2021-10-10 05:23:49 +00:00
msg: "{{ awx_local_media_size_after.stdout.split('\n') }}"
when: awx_purge_media_type == "Local Media"
2021-08-13 08:05:57 +00:00
- name: Print size of remote media repository before purge
debug:
2021-10-10 05:23:49 +00:00
msg: "{{ awx_remote_media_size_before.stdout.split('\n') }}"
when: awx_purge_media_type == "Remote Media"
2021-08-13 08:05:57 +00:00
- name: Print size of remote media repository after purge
debug:
2021-10-10 05:23:49 +00:00
msg: "{{ awx_remote_media_size_after.stdout.split('\n') }}"
when: awx_purge_media_type == "Remote Media"
2021-08-13 08:05:57 +00:00
- name: Delete the AWX session token for executing modules
awx.awx.tower_token:
description: 'AWX Session Token'
scope: "write"
state: absent
existing_token_id: "{{ awx_session_token.ansible_facts.tower_token.id }}"
tower_host: "https://{{ awx_host }}"
tower_oauthtoken: "{{ awx_session_token.ansible_facts.tower_token.token }}"
2021-08-13 08:05:57 +00:00
- name: Set boolean value to exit playbook
set_fact:
2021-10-10 05:23:49 +00:00
awx_end_playbook: true
2021-08-13 08:05:57 +00:00
- name: End playbook early if this task is called.
meta: end_play
2021-10-10 05:23:49 +00:00
when: awx_end_playbook is defined and awx_end_playbook|bool