Ansible role for data presistence and restoration
This can be used for temporary persisting data on undercloud if we want to reprovision the overcloud nodes. Change-Id: If059c477cb2d344fa4c00ce4ea89269c4ef747bd Implements: blueprint upgrades-with-os
This commit is contained in:
parent
5e40539377
commit
6bcdb4fddf
51
roles/tripleo-persist/README.md
Normal file
51
roles/tripleo-persist/README.md
Normal file
@ -0,0 +1,51 @@
|
|||||||
|
tripleo-persist
|
||||||
|
===============
|
||||||
|
|
||||||
|
An Ansible role to temporary persist a files on undercloud and later
|
||||||
|
restore them.
|
||||||
|
|
||||||
|
Role variables
|
||||||
|
--------------
|
||||||
|
|
||||||
|
Required:
|
||||||
|
|
||||||
|
* `tripleo_persist_dir` -- directory on the target host to persist
|
||||||
|
|
||||||
|
Optional:
|
||||||
|
|
||||||
|
* `tripleo_persist_storage_root_dir` -- directory on the Ansible host
|
||||||
|
under which all data is stored
|
||||||
|
(defaults to "/var/lib/mistral/tripleo-persist")
|
||||||
|
* `tripleo_persist_storage_root_become` -- whether to use `become`
|
||||||
|
when creating the storage root directory
|
||||||
|
(defaults to false)
|
||||||
|
|
||||||
|
Test playbook
|
||||||
|
-------------
|
||||||
|
|
||||||
|
Assuming you have tripleo-inventory.yml generated, you can run the
|
||||||
|
test playbook like:
|
||||||
|
|
||||||
|
ANSIBLE_ROLES_PATH=tripleo-common/roles \
|
||||||
|
ANSIBLE_HOST_KEY_CHECKING=False \
|
||||||
|
ansible-playbook
|
||||||
|
-i tripleo-inventory.yml \
|
||||||
|
tripleo-common/roles/tripleo-persist/test-playbook.yml \
|
||||||
|
-e persist=true
|
||||||
|
|
||||||
|
ANSIBLE_ROLES_PATH=tripleo-common/roles \
|
||||||
|
ANSIBLE_HOST_KEY_CHECKING=False \
|
||||||
|
ansible-playbook
|
||||||
|
-i tripleo-inventory.yml \
|
||||||
|
tripleo-common/roles/tripleo-persist/test-playbook.yml \
|
||||||
|
-e restore=true
|
||||||
|
|
||||||
|
License
|
||||||
|
-------
|
||||||
|
|
||||||
|
Free software: Apache License (2.0)
|
||||||
|
|
||||||
|
Author Information
|
||||||
|
------------------
|
||||||
|
|
||||||
|
OpenStack TripleO team
|
2
roles/tripleo-persist/defaults/main.yml
Normal file
2
roles/tripleo-persist/defaults/main.yml
Normal file
@ -0,0 +1,2 @@
|
|||||||
|
tripleo_persist_storage_root_dir: /var/lib/mistral/tripleo-persist
|
||||||
|
tripleo_persist_storage_root_become: false
|
32
roles/tripleo-persist/tasks/persist.yml
Normal file
32
roles/tripleo-persist/tasks/persist.yml
Normal file
@ -0,0 +1,32 @@
|
|||||||
|
- name: ensure local storage directory exists and has correct permissions
|
||||||
|
file:
|
||||||
|
path: "{{tripleo_persist_storage_root_dir}}"
|
||||||
|
# Attempting to set an owner fails with "chown failed: failed to
|
||||||
|
# look up user" so we at least ensure the permissions.
|
||||||
|
mode: 0700
|
||||||
|
state: directory
|
||||||
|
delegate_to: localhost
|
||||||
|
become: "{{tripleo_persist_storage_root_become}}"
|
||||||
|
|
||||||
|
- name: create tempfile for the archive
|
||||||
|
tempfile:
|
||||||
|
prefix: ansible.tripleo-persist.
|
||||||
|
register: tripleo_persist_tempfile
|
||||||
|
|
||||||
|
# Using the "archive" module lists lists all tarred files in module
|
||||||
|
# output, if there's too many files, it can crash ansible even with
|
||||||
|
# "no_log: true".
|
||||||
|
- name: create the archive
|
||||||
|
shell: |
|
||||||
|
tar -czf "{{tripleo_persist_tempfile.path}}" -C "{{tripleo_persist_dir|dirname}}" "{{tripleo_persist_dir|basename}}"
|
||||||
|
|
||||||
|
- name: fetch the archive
|
||||||
|
fetch:
|
||||||
|
src: "{{tripleo_persist_tempfile.path}}"
|
||||||
|
dest: "{{tripleo_persist_storage_root_dir}}/{{inventory_hostname}}{{tripleo_persist_dir}}.tar.gz"
|
||||||
|
flat: yes
|
||||||
|
|
||||||
|
- name: remove tempfile
|
||||||
|
file:
|
||||||
|
name: "{{tripleo_persist_tempfile.path}}"
|
||||||
|
state: absent
|
9
roles/tripleo-persist/tasks/restore.yml
Normal file
9
roles/tripleo-persist/tasks/restore.yml
Normal file
@ -0,0 +1,9 @@
|
|||||||
|
- name: make sure the parent directory is present
|
||||||
|
file:
|
||||||
|
path: "{{tripleo_persist_dir|dirname}}"
|
||||||
|
state: directory
|
||||||
|
|
||||||
|
- name: push and extract the archive
|
||||||
|
unarchive:
|
||||||
|
src: "{{tripleo_persist_storage_root_dir}}/{{inventory_hostname}}{{tripleo_persist_dir}}.tar.gz"
|
||||||
|
dest: "{{tripleo_persist_dir|dirname}}"
|
20
roles/tripleo-persist/test-playbook.yml
Normal file
20
roles/tripleo-persist/test-playbook.yml
Normal file
@ -0,0 +1,20 @@
|
|||||||
|
- hosts: overcloud-controller-0
|
||||||
|
become: true
|
||||||
|
tasks:
|
||||||
|
- name: test tripleo-persist persistence
|
||||||
|
include_role:
|
||||||
|
name: tripleo-persist
|
||||||
|
tasks_from: persist.yml
|
||||||
|
vars:
|
||||||
|
tripleo_persist_dir: /testdir/testsubdir
|
||||||
|
tripleo_persist_storage_root_dir: /home/stack/tripleo-persist
|
||||||
|
when: persist|default(false)|bool
|
||||||
|
|
||||||
|
- name: test tripleo-persist restoration
|
||||||
|
include_role:
|
||||||
|
name: tripleo-persist
|
||||||
|
tasks_from: restore.yml
|
||||||
|
vars:
|
||||||
|
tripleo_persist_dir: /testdir/testsubdir
|
||||||
|
tripleo_persist_storage_root_dir: /home/stack/tripleo-persist
|
||||||
|
when: restore|default(false)|bool
|
Loading…
Reference in New Issue
Block a user