Explorar el Código

Merge pull request #998 from GoMatrixHosting/master

GoMatrixHosting v0.4.2
pull/999/head
Slavi Pantaleev hace 4 años
committed by GitHub
padre
commit
ed3c9ccbd2
No se encontró ninguna clave conocida en la base de datos para esta firma ID de clave GPG: 4AEE18F83AFDEB23
Se han modificado 4 ficheros con 129 adiciones y 0 borrados
  1. +9
    -0
      roles/matrix-awx/tasks/main.yml
  2. +13
    -0
      roles/matrix-awx/tasks/purge_media_local.yml
  3. +94
    -0
      roles/matrix-awx/tasks/purge_media_main.yml
  4. +13
    -0
      roles/matrix-awx/tasks/purge_media_remote.yml

+ 9
- 0
roles/matrix-awx/tasks/main.yml Ver fichero

@@ -26,6 +26,15 @@
tags: tags:
- create-user - create-user


# Purge local/remote media if called
- include_tasks:
file: "purge_media_main.yml"
apply:
tags: purge-media
when: run_setup|bool and matrix_awx_enabled|bool
tags:
- purge-media

# Import configs, media repo from /chroot/backup import # Import configs, media repo from /chroot/backup import
- include_tasks: - include_tasks:
file: "import_awx.yml" file: "import_awx.yml"


+ 13
- 0
roles/matrix-awx/tasks/purge_media_local.yml Ver fichero

@@ -0,0 +1,13 @@

- name: Collect epoche time from date
shell: |
date -d '{{ item }}' +"%s"
register: epoche_time

- name: Purge local media to specific date
shell: |
curl -X POST --header "Authorization: Bearer {{ janitors_token.stdout }}" 'https://matrix.{{ matrix_domain }}/_synapse/admin/v1/media/matrix.{{ matrix_domain }}/delete?before_ts={{ epoche_time.stdout }}'

- name: Pause for 5 seconds to let Synapse breathe
pause:
seconds: 5

+ 94
- 0
roles/matrix-awx/tasks/purge_media_main.yml Ver fichero

@@ -0,0 +1,94 @@

- name: Ensure dateutils and curl is installed in AWX
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
- name: Ensure curl and jq intalled on target machine
apt:
pkg:
- curl
- jq
state: present

- name: Collect access token for janitor user
shell: |
curl -XPOST -d '{"type":"m.login.password", "user":"janitor", "password":"{{ matrix_awx_janitor_user_password }}"}' "https://matrix.{{ matrix_domain }}/_matrix/client/r0/login" | jq '.access_token'
register: janitors_token
- name: Generate list of dates to purge to
delegate_to: 127.0.0.1
shell: "dateseq {{ matrix_purge_from_date }} {{ matrix_purge_to_date }}"
register: purge_dates
- name: Calculate initial size of local media repository
shell: du -sh /matrix/synapse/storage/media-store/local*
register: local_media_size_before
when: matrix_purge_media_type == "Local Media"
ignore_errors: yes
no_log: True

- name: Calculate initial size of remote media repository
shell: du -sh /matrix/synapse/storage/media-store/remote*
register: remote_media_size_before
when: matrix_purge_media_type == "Remote Media"
ignore_errors: yes
no_log: True

- name: Purge local media with loop
include_tasks: purge_media_local.yml
loop: "{{ purge_dates.stdout_lines | flatten(levels=1) }}"
when: matrix_purge_media_type == "Local Media"

- name: Purge remote media with loop
include_tasks: purge_media_remote.yml
loop: "{{ purge_dates.stdout_lines | flatten(levels=1) }}"
when: matrix_purge_media_type == "Remote Media"

- name: Calculate final size of local media repository
shell: du -sh /matrix/synapse/storage/media-store/local*
register: local_media_size_after
when: matrix_purge_media_type == "Local Media"
ignore_errors: yes
no_log: True

- name: Calculate final size of remote media repository
shell: du -sh /matrix/synapse/storage/media-store/remote*
register: remote_media_size_after
when: matrix_purge_media_type == "Remote Media"
ignore_errors: yes
no_log: True

- name: Print size of local media repository before purge
debug:
msg: "{{ local_media_size_before.stdout.split('\n') }}"
when: matrix_purge_media_type == "Local Media"

- name: Print size of local media repository after purge
debug:
msg: "{{ local_media_size_after.stdout.split('\n') }}"
when: matrix_purge_media_type == "Local Media"

- name: Print size of remote media repository before purge
debug:
msg: "{{ remote_media_size_before.stdout.split('\n') }}"
when: matrix_purge_media_type == "Remote Media"

- name: Print size of remote media repository after purge
debug:
msg: "{{ remote_media_size_after.stdout.split('\n') }}"
when: matrix_purge_media_type == "Remote Media"

- name: Set boolean value to exit playbook
set_fact:
end_playbook: true

- name: End playbook early if this task is called.
meta: end_play
when: end_playbook is defined and end_playbook|bool

+ 13
- 0
roles/matrix-awx/tasks/purge_media_remote.yml Ver fichero

@@ -0,0 +1,13 @@

- name: Collect epoche time from date
shell: |
date -d '{{ item }}' +"%s"
register: epoche_time

- name: Purge local media to specific date
shell: |
curl -X POST --header "Authorization: Bearer {{ janitors_token.stdout }}" 'https://matrix.{{ matrix_domain }}/_synapse/admin/v1/purge_media_cache?before_ts={{ epoche_time.stdout }}'

- name: Pause for 5 seconds to let Synapse breathe
pause:
seconds: 5

Cargando…
Cancelar
Guardar