Skip to content

Commit

Permalink
feat: change push_backup props to flat env-var-compatible vars
Browse files Browse the repository at this point in the history
e.g. push_backup.db.addr is now push_backup_db_addr

Backwards compatibility shim is in set-vars role
  • Loading branch information
jamesmontalvo3 committed Oct 3, 2023
1 parent 926f98c commit 07e4bb1
Show file tree
Hide file tree
Showing 6 changed files with 93 additions and 16 deletions.
4 changes: 2 additions & 2 deletions src/playbooks/push-backup.yml
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
- name: Notify push backup is starting
slack:
token: "{{ autodeployer.slack_token }}"
msg: "Push backup to {{ push_backup.short_name | default('remote server') }} starting"
msg: "Push backup to {{ push_backup_short_name | default('remote server') }} starting"
channel: "{{ autodeployer.slack_channel }}"
username: "{{ autodeployer.slack_username }}"
icon_url: "{{ autodeployer_slack_icon_url }}"
Expand Down Expand Up @@ -70,7 +70,7 @@
- name: Notify push backup is complete
slack:
token: "{{ autodeployer.slack_token }}"
msg: "Push backup to {{ push_backup.short_name | default('remote server') }} complete"
msg: "Push backup to {{ push_backup_short_name | default('remote server') }} complete"
channel: "{{ autodeployer.slack_channel }}"
username: "{{ autodeployer.slack_username }}"
icon_url: "{{ autodeployer_slack_icon_url }}"
Expand Down
4 changes: 2 additions & 2 deletions src/roles/autodeployer/templates/meza-autodeployer-cron.j2
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,10 @@ MAILTO=root
{{ autodeployer.crontime }} root meza autodeploy "{{ env }}" "Deploy" "" >> {{ m_logs }}/deploy/check-for-changes-`date "+\%Y\%m\%d"`.log 2>&1


{% if push_backup is defined and push_backup.crontime is defined %}
{% if push_backup is defined and push_backup_crontime is defined %}
#
# Push backup (db and uploads) to another server periodically
#
{{ push_backup.crontime }} root meza push-backup "{{ env }}" >> {{ m_logs }}/deploy/push-backup-`date "+\%Y\%m\%d"`.log 2>&1
{{ push_backup_crontime }} root meza push-backup "{{ env }}" >> {{ m_logs }}/deploy/push-backup-`date "+\%Y\%m\%d"`.log 2>&1
{% endif %}
{% endif %}
12 changes: 6 additions & 6 deletions src/roles/backup-db-wikis-push/tasks/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,29 +14,29 @@

- name: Set remote_server_base_path if set in configuration
set_fact:
remote_server_base_path: "{{ push_backup.db.path }}"
remote_server_base_path: "{{ push_backup_db_path }}"
when:
- push_backup.db.path is defined
- push_backup_db_path is defined

- name: Set remote_server_base_path if NOT set in configuration
set_fact:
remote_server_base_path: "{{ m_backups }}/{{ env }}/<id>/"
when:
- push_backup.db.path is not defined
- push_backup_db_path is not defined

- name: Output value of remote_server_base_path (<id> will be replaced by each wiki_id)
debug: { var: remote_server_base_path }

- name: "Run role:rsync-push - Copy SQL files to {{ push_backup.db.addr }}"
- name: "Run role:rsync-push - Copy SQL files to {{ push_backup_db_addr }}"
include_role:
name: rsync-push
vars:
pushing_from_server: "{{ inventory_hostname }}"
pushing_from_path: "{{ m_tmp }}/{{ env }}_{{ item }}.sql"
pushing_to_server: "{{ push_backup.db.addr }}"
pushing_to_server: "{{ push_backup_db_addr }}"
# remote_server_base_path + backup_timestamp + _wiki.sql, but replace <id> with wiki_id (item)
pushing_to_path: "{{ remote_server_base_path | regex_replace('<id>', item) }}{{ backup_timestamp }}_wiki_push.sql"
pushing_to_user: "{{ push_backup.remote_user }}"
pushing_to_user: "{{ push_backup_remote_user }}"
with_items: "{{ wiki_dirs.files | map(attribute='path') | map('basename') | list }}"

# Remove temp SQL files, only needs to be done on first backup server
Expand Down
12 changes: 6 additions & 6 deletions src/roles/backup-uploads-push/tasks/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,29 +20,29 @@
set_fact:
# Likely path if pushing to a live Meza uploads directory:
# /opt/data-meza/uploads/<wiki_id>/
remote_server_base_path: "{{ push_backup.uploads.path }}"
remote_server_base_path: "{{ push_backup_uploads_path }}"
when:
- push_backup.uploads.path is defined
- push_backup_uploads_path is defined

- name: Set remote_server_base_path if NOT set in configuration
set_fact:
# Likely path if pushing to a Meza backups directory:
# /opt/data-meza/backups/<env>/<wiki_id>/uploads/
remote_server_base_path: "{{ m_backups }}/{{ env }}/<id>/uploads/"
when:
- push_backup.uploads.path is not defined
- push_backup_uploads_path is not defined

- name: Output value of remote_server_base_path (<id> will be replaced by each wiki_id)
debug: { var: remote_server_base_path }

- name: "Run role:rsync-push - Copy uploads directory to {{ push_backup.uploads.addr }}"
- name: "Run role:rsync-push - Copy uploads directory to {{ push_backup_uploads_addr }}"
include_role:
name: rsync-push
vars:
pushing_from_server: "{{ inventory_hostname }}"
pushing_from_path: "{{ m_uploads_dir }}/{{ item }}/"
pushing_to_server: "{{ push_backup.uploads.addr }}"
pushing_to_server: "{{ push_backup_uploads_addr }}"
# remote_server_base_path + backup_timestamp, but replace <id> with wiki_id (item)
pushing_to_path: "{{ remote_server_base_path | regex_replace('<id>', item) }}"
pushing_to_user: "{{ push_backup.remote_user }}"
pushing_to_user: "{{ push_backup_remote_user }}"
with_items: "{{ wiki_dirs.files | map(attribute='path') | map('basename') | list }}"
6 changes: 6 additions & 0 deletions src/roles/set-vars/tasks/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -75,3 +75,9 @@
# Can't load secret.yml when it doesn't exist yet, so skip this while setting
# up an environment
when: not allow_missing_secret_config|default(false)

#
# Misc
#
- name: Include push_backup backwards compatibility
include: push-backup.yml
71 changes: 71 additions & 0 deletions src/roles/set-vars/tasks/push-backup.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
---
#
# Set variables associated with pushing backups. Previously these variables were only
# set like:
#
# push_backup:
# crontime: "0 18 * * *"
# remote_user: meza-ansible
# short_name: "staging"
# db:
# addr: "staging.example.com"
# path: /opt/data-meza/backups/staging/<id>/
# uploads:
# addr: "staging.example.com"
# path: /opt/data-meza/uploads/<id>
#
# In order to support running push-backup only with environment variables, the above
# variables (which are all properties based off push_backup root variable) have been
# re-written in the following form:
#
# push_backup.db.addr --> push_backup_db_addr
#
# This file enables backwards compatibility by taking values like `push_backup.db.addr`
# and creating `push_backup_db_addr`.
#

- set_fact:
push_backup_crontime: "{{ push_backup.crontime }}"
when:
- push_backup is defined
- push_backup.crontime is defined

- set_fact:
push_backup_remote_user: "{{ push_backup.remote_user }}"
when:
- push_backup is defined
- push_backup.remote_user is defined

- set_fact:
push_backup_short_name: "{{ push_backup.short_name }}"
when:
- push_backup is defined
- push_backup.short_name is defined

- set_fact:
push_backup_db_addr: "{{ push_backup.db.addr }}"
when:
- push_backup is defined
- push_backup.db is defined
- push_backup.db.addr is defined

- set_fact:
push_backup_db_path: "{{ push_backup.db.path }}"
when:
- push_backup is defined
- push_backup.db is defined
- push_backup.db.path is defined

- set_fact:
push_backup_uploads_addr: "{{ push_backup.uploads.addr }}"
when:
- push_backup is defined
- push_backup.uploads is defined
- push_backup.uploads.addr is defined

- set_fact:
push_backup_uploads_path: "{{ push_backup.uploads.path }}"
when:
- push_backup is defined
- push_backup.uploads is defined
- push_backup.uploads.path is defined

0 comments on commit 07e4bb1

Please sign in to comment.