Backup and Restore using Ansible Playbook
This commit fixes some bugs in backup and restore_platform playbook: 1. ansible_port is not defined. 2. The pre-tasks in restore_platform playbook should be delegated to localhost. 3. KUBECONFIG environment variable cannot be retrieved via lookup plugins because these plugins are evaluated on the Ansible control machine. 4. Add a check for /opt/platform/config/<version>/ssh_config before restore it. It also adds loop_control to reduce output when estimating the backup size. Change-Id: I3e54a923460f817e4082269cc97b2613396db896 Story: 2004761 Task: 36044 Signed-off-by: Wei Zhou <wei.zhou@windriver.com>
This commit is contained in:
parent
4b9ea63d4f
commit
9984a93359
|
@ -169,6 +169,8 @@
|
|||
set_fact:
|
||||
total_size_estimation: "{{ total_size_estimation|default(1024*128)|int + item.stdout|int }}"
|
||||
with_items: "{{ size_output.results }}"
|
||||
loop_control:
|
||||
label: "{{ item.item }}"
|
||||
|
||||
- name: Check if there is enough free space in the archive dir to create backup
|
||||
shell: "df -k /opt/backups --output=avail | tail -1"
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
---
|
||||
kube_config_dir: "{{ lookup('env', 'KUBECONFIG') }}"
|
||||
kube_config_dir: /etc/kubernetes/admin.conf
|
||||
|
||||
skip_os_dbs: ['Database', 'information_schema', 'performance_schema', 'mysql', 'horizon', 'panko', 'gnocchi']
|
||||
|
||||
|
|
|
@ -8,7 +8,12 @@
|
|||
# This role contains common components (tasks, vars, etc.) that
|
||||
# can be shared by all the backup and restore playbooks.
|
||||
|
||||
# Check host connectivity
|
||||
- block:
|
||||
- name: Set SSH port
|
||||
set_fact:
|
||||
ansible_port: "{{ ansible_port | default(22) }}"
|
||||
|
||||
- name: Update SSH known hosts
|
||||
lineinfile:
|
||||
path: ~/.ssh/known_hosts
|
||||
|
|
|
@ -7,5 +7,5 @@
|
|||
|
||||
platform_permdir: /opt/platform
|
||||
restore_openstack_in_progress_flag: "{{ platform_permdir }}/.restore_openstack_in_progress"
|
||||
kube_config_dir: "{{ lookup('env', 'KUBECONFIG') }}"
|
||||
kube_config_dir: /etc/kubernetes/admin.conf
|
||||
mariadb_pod: mariadb-server-0
|
||||
|
|
|
@ -4,50 +4,53 @@
|
|||
#
|
||||
# SPDX-License-Identifier: Apache-2.0
|
||||
#
|
||||
- hosts: localhost
|
||||
- hosts: all
|
||||
gather_facts: no
|
||||
|
||||
vars_files:
|
||||
- host_vars/default.yml
|
||||
|
||||
pre_tasks:
|
||||
- name: Fail if backup_filename is not defined or set
|
||||
fail:
|
||||
msg: "Mandatory configuration parameter backup_filename is not defined or set."
|
||||
when: backup_filename is not defined or backup_filename is none
|
||||
|
||||
- name: Look for override backup file in the backup tarball
|
||||
shell: "tar -tf {{ host_backup_dir }}/{{ backup_filename }} | grep '_override_backup.yml'"
|
||||
args:
|
||||
warn: false
|
||||
failed_when: false
|
||||
register: search_result
|
||||
|
||||
- block:
|
||||
- name: Extract override backup file
|
||||
shell: >-
|
||||
tar -C {{ override_files_dir }} -xf {{ host_backup_dir }}/{{ backup_filename }} --transform='s,.*/,,'
|
||||
{{ search_result.stdout_lines[0] }}
|
||||
- name: Fail if backup_filename is not defined or set
|
||||
fail:
|
||||
msg: "Mandatory configuration parameter backup_filename is not defined or set."
|
||||
when: backup_filename is not defined or backup_filename is none
|
||||
|
||||
- name: Look for override backup file in the backup tarball
|
||||
shell: "tar -tf {{ host_backup_dir }}/{{ backup_filename }} | grep '_override_backup.yml'"
|
||||
args:
|
||||
warn: false
|
||||
failed_when: false
|
||||
register: search_result
|
||||
|
||||
- name: Prepare to rename override file
|
||||
set_fact:
|
||||
override_filename: "{{ (search_result.stdout_lines[0] | basename).split('_')[0] }}.yml"
|
||||
- block:
|
||||
- name: Extract override backup file
|
||||
shell: >-
|
||||
tar -C {{ override_files_dir }} -xf {{ host_backup_dir }}/{{ backup_filename }} --transform='s,.*/,,'
|
||||
{{ search_result.stdout_lines[0] }}
|
||||
args:
|
||||
warn: false
|
||||
|
||||
- name: Rename override file
|
||||
command: >-
|
||||
mv {{ override_files_dir }}/{{ (search_result.stdout_lines[0] | basename) }}
|
||||
{{ override_files_dir }}/{{ override_filename }}
|
||||
- name: Prepare to rename override file
|
||||
set_fact:
|
||||
override_filename: "{{ (search_result.stdout_lines[0] | basename).split('_override_backup')[0] }}.yml"
|
||||
|
||||
when: search_result.rc == 0
|
||||
- name: Rename override file
|
||||
command: >-
|
||||
mv -f {{ override_files_dir }}/{{ (search_result.stdout_lines[0] | basename) }}
|
||||
{{ override_files_dir }}/{{ override_filename }}
|
||||
|
||||
- name: Fail if override file is missing
|
||||
fail:
|
||||
msg: >-
|
||||
Cannot find {{ host_backup_dir }}/{{ backup_filename }}
|
||||
or the override file is missing in the backup tarball!
|
||||
when: search_result.rc != 0
|
||||
when: search_result.rc == 0
|
||||
|
||||
- name: Fail if override file is missing
|
||||
fail:
|
||||
msg: >-
|
||||
Cannot find {{ host_backup_dir }}/{{ backup_filename }}
|
||||
or the override file is missing in the backup tarball!
|
||||
when: search_result.rc != 0
|
||||
|
||||
delegate_to: localhost
|
||||
|
||||
- name: Run bootstrap playbook with restore mode
|
||||
import_playbook: bootstrap.yml mode='restore'
|
||||
|
|
|
@ -48,26 +48,35 @@
|
|||
args:
|
||||
warn: false
|
||||
|
||||
- name: Create temp ssh_config dir
|
||||
file:
|
||||
path: "{{ temp_ssh_config_dir }}"
|
||||
state: directory
|
||||
owner: root
|
||||
group: root
|
||||
mode: 0755
|
||||
|
||||
- name: Prefetch ssh_config
|
||||
command: >-
|
||||
tar -C {{ temp_ssh_config_dir }} -xpf {{ staging_dir }}/{{ backup_filename }} --transform='s,.*/,,'
|
||||
{{ short_ssh_config_permdir }}
|
||||
- name: Look for ssh_config dir in the backup tarball
|
||||
shell: "tar -tf {{ staging_dir }}/{{ backup_filename }} | grep 'opt/platform/config/.*/ssh_config'"
|
||||
args:
|
||||
warn: false
|
||||
failed_when: false
|
||||
register: search_ssh_config
|
||||
|
||||
- name: Remove the unwanted directory
|
||||
file:
|
||||
path: "{{ temp_ssh_config_dir }}/ssh_config"
|
||||
state: absent
|
||||
- block:
|
||||
- name: Create temp ssh_config dir
|
||||
file:
|
||||
path: "{{ temp_ssh_config_dir }}"
|
||||
state: directory
|
||||
owner: root
|
||||
group: root
|
||||
mode: 0755
|
||||
|
||||
- name: Prefetch ssh_config
|
||||
command: >-
|
||||
tar -C {{ temp_ssh_config_dir }} -xpf {{ staging_dir }}/{{ backup_filename }} --transform='s,.*/,,'
|
||||
{{ short_ssh_config_permdir }}
|
||||
args:
|
||||
warn: false
|
||||
|
||||
- name: Remove the unwanted directory
|
||||
file:
|
||||
path: "{{ temp_ssh_config_dir }}/ssh_config"
|
||||
state: absent
|
||||
|
||||
when: search_ssh_config.rc == 0
|
||||
when: mode == 'restore'
|
||||
|
||||
- name: Applying puppet bootstrap manifest
|
||||
|
|
Loading…
Reference in New Issue