ansible-playbooks/playbookconfig/src/playbooks/roles/restore-platform/prepare-env/tasks/main.yml

98 lines
3.1 KiB
YAML

---
#
# Copyright (c) 2019 Wind River Systems, Inc.
#
# SPDX-License-Identifier: Apache-2.0
#
# ROLE DESCRIPTION:
# This role performs following tasks:
# 1. Retrieve the override file from the backup tarball
# required for the controller bootstrap.
# 2. Verify if platform restore should proceed
#
- block:
- 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: Fail if initial_backup_dir is not defined or set
fail:
msg: "Mandatory configuration parameter initial_backup_dir is not defined or set."
when: initial_backup_dir is not defined or initial_backup_dir is none
- name: Look for override backup file in the backup tarball
shell: "tar -tf {{ initial_backup_dir }}/{{ backup_filename }} | grep '_override_backup.yml'"
args:
warn: false
failed_when: false
register: search_result
- block:
- name: Extract override file from backup tarball
shell: >-
tar -C {{ override_files_dir }} -xf {{ initial_backup_dir }}/{{ backup_filename }} --transform='s,.*/,,'
{{ search_result.stdout_lines[0] }}
args:
warn: false
- name: Prepare to rename override file
set_fact:
override_filename: "{{ (search_result.stdout_lines[0] | basename).split('_override_backup')[0] }}.yml"
- name: Rename override file for bootstrap
command: >-
mv -f {{ override_files_dir }}/{{ (search_result.stdout_lines[0] | basename) }}
{{ override_files_dir }}/{{ override_filename }}
when: search_result.rc == 0
- name: Fail if override file is missing
fail:
msg: >-
Cannot find {{ initial_backup_dir }}/{{ backup_filename }}
or the override file is missing in the backup tarball!
when: search_result.rc != 0
delegate_to: localhost
- block:
# Bail if the host has been unlocked
- name: Check initial config flag
stat:
path: /etc/platform/.initial_config_complete
register: initial_config_done
- name: Fail if the host has been unlocked
fail:
msg: "Host {{ ansible_host }} has been unlocked. Cannot perform restore."
when: initial_config_done.stat.exists
- name: Check if restore is in progress if bootstrap is with restore mode
stat:
path: "{{ restore_in_progress_flag }}"
register: restore_in_progress
- name: Fail if restore is already in progress
fail:
msg: " Restore is already in progress!"
when: restore_in_progress.stat.exists
- name: Create {{ restore_in_progress_flag }} flag file
file:
path: "{{ restore_in_progress_flag }}"
state: touch
- name: For remote play set target_backup_dir to /scratch
set_fact:
target_backup_dir: /scratch
when: inventory_hostname != "localhost"
- name: For local play set target_backup_dir to initial_backup_dir
set_fact:
target_backup_dir: "{{ initial_backup_dir }}"
when: inventory_hostname == "localhost"
become: yes
become_user: root