Merge "Add append option to tripleo_derive_hci_parameters module"

This commit is contained in:
Zuul 2021-05-03 22:17:50 +00:00 committed by Gerrit Code Review
commit 061bea8b1b
5 changed files with 37 additions and 15 deletions

View File

@ -15,6 +15,7 @@
# under the License.
"""Derive paramters for HCI (hyper-converged) deployments"""
import os
import re
import yaml
@ -64,6 +65,10 @@ options:
description: Path to file new where resultant derived parameters will be written; result will be valid input to TripleO client, e.g. /home/stack/derived_paramaters.yaml
required: False
type: str
append_new_heat_environment_path:
description: If new_heat_environment_path already exists and append_new_heat_environment_path is true, then append new content to the existing new_heat_environment_path instead of overwriting a new version of that file.
required: False
type: bool
report_path:
description: Path to file new where a report on how HCI paramters were derived be written, e.g. /home/stack/hci_derived_paramaters.txt
required: False
@ -446,6 +451,7 @@ def main():
average_guest_memory_size_in_mb=dict(type=int, required=False, default=0),
derived_parameters=dict(type=dict, required=False),
new_heat_environment_path=dict(type=str, required=False),
append_new_heat_environment_path=dict(type=bool, required=False),
report_path=dict(type=str, required=False),
)
module = AnsibleModule(
@ -491,8 +497,29 @@ def main():
existing_params[role_name_parameters] = role_derivation
# write out to file if requested
if module.params['new_heat_environment_path'] and not module.check_mode:
output = {}
output['parameter_defaults'] = existing_params
if module.params['append_new_heat_environment_path'] and \
os.path.exists(module.params['new_heat_environment_path']):
with open(module.params['new_heat_environment_path'], 'r') as stream:
try:
output = yaml.safe_load(stream)
if 'parameter_defaults' in output:
output['parameter_defaults'][role_name_parameters] = \
role_derivation
else:
result['failed'] = True
result['message'] = ("tripleo_derive_hci_parameters module "
"cannot append to environment file %s. "
"It is missing the 'parameter_defaults' "
"key. Try again with the parameter "
"append_new_heat_environment_path set "
"False") \
% module.params['new_heat_environment_path']
except yaml.YAMLError as exc:
result['failed'] = True
result['message'] = exec
else:
output = {}
output['parameter_defaults'] = existing_params
with open(module.params['new_heat_environment_path'], 'w') as outfile:
yaml.safe_dump(output, outfile, default_flow_style=False)
# because we wrote a file we're making a change on the target system

View File

@ -54,19 +54,8 @@
tripleo_role_name: "{{ outer_item }}"
tripleo_environment_parameters: "{{ tripleo_get_flatten_params.stack_data.environment_parameters }}"
tripleo_heat_resource_tree: "{{ tripleo_get_flatten_params.stack_data.heat_resource_tree }}"
new_heat_environment_path: "{{ derived_environment_path }}"
append_new_heat_environment_path: True
loop: "{{ tripleo_role_list.roles }}"
loop_control:
loop_var: outer_item
- name: Write environment to {{ derived_environment_path }}
block:
- name: create derived params dictionary
set_fact:
derived_params_env: "{{ {'parameter_defaults': derived_parameters_result['derived_parameters'] | default({})} }}"
- name: Write environment
copy:
dest: "{{ derived_environment_path }}"
content: "{{ derived_params_env | to_nice_yaml(indent=2) }}"
when:
- derived_environment_path is defined
- derived_parameters_result is defined

View File

@ -23,3 +23,5 @@ tripleo_plan_name: Overcloud
tripleo_role_name: undefined
tripleo_environment_parameters: {}
tripleo_heat_resource_tree: {}
new_heat_environment_path: ""
append_new_heat_environment_path: false

View File

@ -36,6 +36,8 @@
tripleo_environment_parameters: "{{ tripleo_get_flatten_params.stack_data.environment_parameters }}"
tripleo_heat_resource_tree: "{{ tripleo_get_flatten_params.stack_data.heat_resource_tree }}"
baremetal_data: "{{ lookup('file', '../mock_baremetal_{{ outer_item }}') | from_yaml }}"
new_heat_environment_path: ""
append_new_heat_environment_path: false
loop: "{{ tripleo_role_list.roles }}"
loop_control:
loop_var: outer_item

View File

@ -206,6 +206,8 @@
average_guest_cpu_utilization_percentage: "{{ average_guest_cpu_utilization_percentage }}"
average_guest_memory_size_in_mb: "{{ average_guest_memory_size_in_mb }}"
derived_parameters: "{{ derived_parameters }}"
new_heat_environment_path: "{{ new_heat_environment_path }}"
append_new_heat_environment_path: "{{ append_new_heat_environment_path }}"
register: derived_parameters_result
- name: Show HCI derived paramters results