Add append option to tripleo_derive_hci_parameters module
The module already has the parameter new_heat_environment_path, which is a path to a file that gets overwritten each time the module is called. Add append_new_heat_environment_path, which is a new bool parameter that defaults to false to perserve the existing behavior. If the new parameter is true, then merge the new derived paramters into the file without loosing the existing derived paramters already in the file. To close bug 1926627, use new_heat_environment_path with the new option in the existing role loop. Also, remove the unnecessary task to write out the derived_parameter_result variable because we now write it in the previous task. Closes-Bug: #1926627 Change-Id: Iabb0cbda57fabf27d0e5d8b1cc75706785ecd967
This commit is contained in:
parent
c72a83c30c
commit
756454f4b6
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
|
Loading…
Reference in New Issue