You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
147 lines
5.3 KiB
YAML
147 lines
5.3 KiB
YAML
---
|
|
|
|
# ****** ** ****** ** ** ** ** ******* #
|
|
# /*////** **** **////** /** ** /** /** /**////** #
|
|
# /* /** **//** ** // /** ** /** /** /** /** #
|
|
# /****** ** //** /** /**** /** /** /******* #
|
|
# /*//// ** ********** /** /**/** /** /** /**//// #
|
|
# /* /** /**//////** //** ** /**//** /** /** /** #
|
|
# /******* /** /** //****** /** //** //******* /** #
|
|
# /////// // // ////// // // /////// // #
|
|
|
|
# creates remote database backup
|
|
# - postgres
|
|
# - executed on stage specific server: {{ shared_service_postgres_secondary }} (currently: slave)
|
|
# - creates database backup for ALL databases in postgres-server
|
|
# - mariadb
|
|
# - executed on stage specific server: {{ shared_service_maria_primary }}
|
|
# - creates database backup for ALL databases in mariadb-server
|
|
|
|
# Parameters:
|
|
# playbook inventory
|
|
# stage := the name of the stage (e.g. dev, int, qa, prod)
|
|
# database_engine := the database engine to generate a complete backup for (e.g. postgres, maria)
|
|
# smardigo message callback
|
|
# scope_id := (scope id of the management process)
|
|
# process_instance_id := (process instance id of the management process)
|
|
# smardigo_management_action := (smardigo management action anme of the management process)
|
|
|
|
#############################################################
|
|
# Creating inventory dynamically for given parameters
|
|
#############################################################
|
|
|
|
- hosts: localhost
|
|
connection: local
|
|
gather_facts: false
|
|
|
|
tasks:
|
|
# add virtual server to load stage specific variables as context
|
|
- name: "Add <{{ stage }}-virtual-host-to-read-groups-vars> to hosts"
|
|
add_host:
|
|
name: "{{ stage }}-virtual-host-to-read-groups-vars"
|
|
groups:
|
|
- "stage_{{ stage }}"
|
|
changed_when: False
|
|
|
|
- hosts: "{{ stage }}-virtual-host-to-read-groups-vars"
|
|
serial: "{{ serial_number | default(1) }}"
|
|
gather_facts: false
|
|
connection: local
|
|
|
|
pre_tasks:
|
|
- name: "Import constraints check"
|
|
import_tasks: tasks/constraints_check.yml
|
|
tags:
|
|
- always
|
|
|
|
tasks:
|
|
- name: "Add {{ database_engine }} servers to hosts if necessary"
|
|
add_host:
|
|
name: "{{shared_service_postgres_secondary }}"
|
|
groups:
|
|
- "stage_{{ stage }}"
|
|
- '{{ database_engine }}'
|
|
when:
|
|
- database_engine in ['postgres']
|
|
|
|
- name: "Add {{ database_engine }} servers to hosts if necessary"
|
|
add_host:
|
|
name: "{{ shared_service_maria_primary }}"
|
|
groups:
|
|
- "stage_{{ stage }}"
|
|
- '{{ database_engine }}'
|
|
when:
|
|
- database_engine in ['maria']
|
|
|
|
- name: "Add 'storage' servers to hosts if necessary"
|
|
add_host:
|
|
name: "{{ stage }}-backup-01"
|
|
groups:
|
|
- "stage_{{ stage }}"
|
|
- "storage"
|
|
|
|
##############################################################
|
|
## Creating remote database backups for created inventory
|
|
##############################################################
|
|
|
|
- hosts: "postgres:maria"
|
|
serial: "{{ serial_number | default(1) }}"
|
|
gather_facts: false
|
|
vars:
|
|
ansible_ssh_host: "{{ stage_server_domain }}"
|
|
current_date_time: '{{ get_current_date_time }}'
|
|
|
|
tasks:
|
|
- name: "Trigger backup mechanism"
|
|
include_role:
|
|
name: '{{ database_engine }}'
|
|
tasks_from: _create_backup
|
|
|
|
#############################################################
|
|
# Syncing remote database backups to storage server
|
|
#############################################################
|
|
|
|
- hosts: "postgres:maria:storage"
|
|
serial: "{{ serial_number | default(5) }}"
|
|
gather_facts: false
|
|
vars:
|
|
ansible_ssh_host: "{{ stage_server_domain }}"
|
|
storageserver_system_user: 'backuphamster'
|
|
|
|
tasks:
|
|
# I could not get it up and running with <synchronize> module
|
|
# to sync data from remote server A to remote server B
|
|
- name: "Syncing remote backups"
|
|
become: yes
|
|
become_user: '{{ storageserver_system_user }}'
|
|
vars:
|
|
# should work with non-fqdn due to existing entry in /etc/hosts
|
|
database_server_ip: "{{ stage }}-{{ database_engine }}-{{'02' if database_engine == 'postgres' else '01'}}"
|
|
shell: '/home/{{ storageserver_system_user }}/pull_remote_backups.sh {{ database_server_ip }} {{ stage }} {{ database_engine }}'
|
|
when:
|
|
- inventory_hostname in groups['storage']
|
|
|
|
- name: "Cleanup remote backup dirs: {{ database_engine }}"
|
|
become: yes
|
|
file:
|
|
path: '{{ backup_directory }}/{{ database_engine }}/{{ get_current_date }}'
|
|
state: absent
|
|
when:
|
|
- not inventory_hostname in groups['storage']
|
|
|
|
#############################################################
|
|
# Sending smardigo management message to process
|
|
#############################################################
|
|
|
|
- hosts: "{{ stage }}-virtual-host-to-read-groups-vars"
|
|
serial: "{{ serial_number | default(1) }}"
|
|
gather_facts: false
|
|
connection: local
|
|
run_once: true
|
|
vars:
|
|
connect_jwt_username: "{{ management_admin_username }}"
|
|
|
|
tasks:
|
|
- name: "Sending smardigo management message to <{{ shared_service_url_management }}>"
|
|
include_tasks: tasks/smardigo_management_message.yml
|