Ansible role to transfer data from an overcloud node to another

This will be used when doing canary-like controller upgrade with
reprovisioning. We'll transfer DB data from a recently stopped old
node to a new reprovisioned node to bootstrap a new controller
cluster.

Change-Id: I4afbfb5094c43aa4bca21968dca7b4d3cd56aef0
Implements: blueprint upgrades-with-os
This commit is contained in:
Jiri Stransky
2019-01-16 16:58:54 +01:00
committed by Sofer Athlan-Guyot
parent 6bcdb4fddf
commit 75af95b78d
4 changed files with 140 additions and 0 deletions

View File

@@ -0,0 +1,57 @@
tripleo-transfer
================
An Ansible role to files from one overcloud node to another one.
Role variables
--------------
Required:
* `tripleo_transfer_src_host` -- the inventory name of the source host
* `tripleo_transfer_src_dir` -- directory on the source host to
transfer from
* `tripleo_transfer_dest_host` -- the inventory name of the
destination host
* `tripleo_transfer_dest_dir` -- directory on the destination host to
transfer to
Optional:
* `tripleo_transfer_storage_root_dir` -- directory on the Ansible host
under which all data is temporarily stored
(defaults to "/var/lib/mistral/tripleo-transfer")
* `tripleo_transfer_storage_root_become` -- whether to use `become`
when creating the storage root directory
(defaults to false)
* `tripleo_transfer_src_become` -- whether to use `become`
on the source host
(defaults to true)
* `tripleo_transfer_dest_become` -- whether to use `become`
on the destination host
(defaults to true)
* `tripleo_transfer_dest_wipe` -- whether to wipe the destination
directory before transferring the content
(defaults to true)
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-transfer/test-playbook.yml
License
-------
Free software: Apache License (2.0)
Author Information
------------------
OpenStack TripleO team

View File

@@ -0,0 +1,5 @@
tripleo_transfer_storage_root_dir: /var/lib/mistral/tripleo-transfer
tripleo_transfer_storage_root_become: false
tripleo_transfer_src_become: true
tripleo_transfer_dest_become: true
tripleo_transfer_dest_wipe: true

View File

@@ -0,0 +1,67 @@
- name: ensure local storage directory exists and has correct permissions
file:
path: "{{tripleo_transfer_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_transfer_storage_root_become}}"
- name: create tempfile for the archive
tempfile:
prefix: ansible.tripleo-transfer.
register: tripleo_transfer_tempfile
become: "{{tripleo_transfer_src_become}}"
delegate_to: "{{tripleo_transfer_src_host}}"
# 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 --transform "s|^{{tripleo_transfer_src_dir|basename}}|{{tripleo_transfer_dest_dir|basename}}|" -czf "{{tripleo_transfer_tempfile.path}}" -C "{{tripleo_transfer_src_dir|dirname}}" "{{tripleo_transfer_src_dir|basename}}"
become: "{{tripleo_transfer_src_become}}"
delegate_to: "{{tripleo_transfer_src_host}}"
- name: fetch the archive
fetch:
src: "{{tripleo_transfer_tempfile.path}}"
dest: "{{tripleo_transfer_storage_root_dir}}/{{tripleo_transfer_dest_host}}{{tripleo_transfer_dest_dir}}.tar.gz"
flat: yes
become: "{{tripleo_transfer_src_become}}"
delegate_to: "{{tripleo_transfer_src_host}}"
- name: remove tempfile
file:
name: "{{tripleo_transfer_tempfile.path}}"
state: absent
become: "{{tripleo_transfer_src_become}}"
delegate_to: "{{tripleo_transfer_src_host}}"
- name: wipe the destination directory
file:
path: "{{tripleo_transfer_dest_dir}}"
state: absent
become: "{{tripleo_transfer_dest_become}}"
delegate_to: "{{tripleo_transfer_dest_host}}"
when: tripleo_transfer_dest_wipe|bool
- name: make sure the destination parent directory is present
file:
path: "{{tripleo_transfer_dest_dir|dirname}}"
state: directory
become: "{{tripleo_transfer_dest_become}}"
delegate_to: "{{tripleo_transfer_dest_host}}"
- name: push and extract the archive
unarchive:
src: "{{tripleo_transfer_storage_root_dir}}/{{tripleo_transfer_dest_host}}{{tripleo_transfer_dest_dir}}.tar.gz"
dest: "{{tripleo_transfer_dest_dir|dirname}}"
become: "{{tripleo_transfer_dest_become}}"
delegate_to: "{{tripleo_transfer_dest_host}}"
- name: remove the local archive
file:
path: "{{tripleo_transfer_storage_root_dir}}/{{tripleo_transfer_dest_host}}{{tripleo_transfer_dest_dir}}.tar.gz"
state: absent

View File

@@ -0,0 +1,11 @@
- hosts: undercloud
tasks:
- name: test tripleo-transfer
include_role:
name: tripleo-transfer
vars:
tripleo_transfer_src_host: overcloud-controller-0
tripleo_transfer_src_dir: /srcdir/srcsubdir
tripleo_transfer_dest_host: overcloud-controller-1
tripleo_transfer_dest_dir: /destdir/destsubdir
tripleo_transfer_storage_root_dir: /home/stack/tripleo-transfer