New role to create/update/delete hiera value during upgrade.

We need to override the cluster definition during upgrade, so that we
can build a one node cluster followed by a two and three nodes
cluster.

Change-Id: Id55a4ea7f0e8a8d95a49ba93853cf7844d938f43
Implements: blueprint upgrades-with-os
This commit is contained in:
Sofer Athlan-Guyot 2019-01-17 12:51:14 +01:00
parent 75af95b78d
commit de7df308e0
7 changed files with 151 additions and 0 deletions

View File

@ -0,0 +1,39 @@
tripleo-upgrade-hiera
=====================
An Ansible role to set hiera value during upgrade as json value/key.
Role variables
--------------
Required:
* `tripleo_upgrade_key` -- the hiera key to setup. (optional for remove_all)
* `tripleo_upgrade_value` -- the hiera value to setup. (non-needed for remove and remove_all)
Optional:
* `tripleo_upgrade_hiera_file` -- hiera file to were the variable go.
(defaults to "/etc/puppet/hieradata/upgrade.json")
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-upgrade-hiera/test-playbook.yml
License
-------
Free software: Apache License (2.0)
Author Information
------------------
OpenStack TripleO team

View File

@ -0,0 +1 @@
tripleo_upgrade_hiera_file: /etc/puppet/hieradata/upgrade.json

View File

@ -0,0 +1,35 @@
- name: create the directory for hiera file
file:
path: "{{tripleo_upgrade_hiera_file|dirname}}"
owner: "root"
group: "root"
mode: 0755
state: directory
become: yes
- name: check if the upgrade file exists.
stat:
path: "{{tripleo_upgrade_hiera_file}}"
register: _tripleo_upgrade_hiera_file
become: yes
- name: check if the file contains valid json
command: "jq . {{tripleo_upgrade_hiera_file}}"
register: _tripleo_upgrade_hiera_test
become: yes
when: _tripleo_upgrade_hiera_file.stat.exists
- name: create the hiera file when no file or empty file.
copy:
dest: "{{tripleo_upgrade_hiera_file}}"
owner: "root"
group: "root"
mode: 0644
content: "{}"
become: yes
when: not _tripleo_upgrade_hiera_file.stat.exists or _tripleo_upgrade_hiera_test.stdout == ""
- name: load the json hiera data
command: "jq . {{tripleo_upgrade_hiera_file}}"
register: tripleo_upgrade_hiera_command
become: yes

View File

@ -0,0 +1,6 @@
---
- name: delete the upgrade hiera file
file:
path: "{{tripleo_upgrade_hiera_file}}"
state: absent
become: yes

View File

@ -0,0 +1,16 @@
---
- name: ensure tripleo-upgrade hiera file exists
include_tasks: create-tripleo-upgrade-file.yml
- name: remove a tripleo-upgrade key
set_fact:
tripleo_upgrade_hiera_data_del: "{{ tripleo_upgrade_hiera_data_del|default({})|combine({item.key: item.value}) }}"
cacheable: no
when: item.key != tripleo_upgrade_key
with_dict: "{{ tripleo_upgrade_hiera_command.stdout | from_json | default({}) }}"
- name: write the updated tripleo-upgrade hiera data
copy:
content: "{{ tripleo_upgrade_hiera_data_del | to_nice_json }}"
dest: "{{tripleo_upgrade_hiera_file}}"
become: yes

View File

@ -0,0 +1,15 @@
---
- name: ensure tripleo-upgrade hiera file exists
include_tasks: create-tripleo-upgrade-file.yml
- name: set/update the tripleo-upgrade key/value
set_fact:
tripleo_upgrade_hiera_data_add: "{{ tripleo_upgrade_hiera_command.stdout | from_json | combine({ tripleo_upgrade_key: tripleo_upgrade_value }) }}"
cacheable: no
- name: write the updated tripleo-upgrade hiera data
copy:
content: "{{ tripleo_upgrade_hiera_data_add | to_nice_json }}"
dest: "{{tripleo_upgrade_hiera_file}}"
become: yes

View File

@ -0,0 +1,39 @@
- hosts: controller-0
gather_facts: false
become: true
tasks:
- name: test tripleo-upgrade-hiera - add a first value
include_role:
name: tripleo-upgrade-hiera
tasks_from: set.yml
vars:
tripleo_upgrade_key: pacemaker_short_node_names_override
tripleo_upgrade_value: [ "controller-0" ]
- name: test tripleo-upgrade-hiera - add another value
include_role:
name: tripleo-upgrade-hiera
tasks_from: set.yml
vars:
tripleo_upgrade_key: mysql_short_node_names_override
tripleo_upgrade_value: [ "controller-0", "controller-1" ]
- name: test tripleo-upgrade-hiera - update a value
include_role:
name: tripleo-upgrade-hiera
tasks_from: set.yml
vars:
tripleo_upgrade_key: mysql_short_node_names_override
tripleo_upgrade_value: [ "controller-1" ]
- name: test tripleo-upgrade-hiera - remove a value
include_role:
name: tripleo-upgrade-hiera
tasks_from: remove.yml
vars:
tripleo_upgrade_key: pacemaker_short_node_names_override
- name: test tripleo-upgrade-hiera - remove all values
include_role:
name: tripleo-upgrade-hiera
tasks_from: remove-all.yml