Format group:ansible deployments
The group:ansible deployments were not formatted as human readable in the group_vars. It was all just one long line. This made manual review and debugging more difficult. It should instead be in a human readable format. To accomplish that, we first attempt to convert the config value to JSON, then pretty print it. Change-Id: I1916d0378d4687966ec7b01f022e70c10e813f3c Closes-Bug: #1745241
This commit is contained in:
parent
bd3476ff54
commit
70df1c1381
@ -0,0 +1,6 @@
|
||||
---
|
||||
fixes:
|
||||
- The group:ansible deployments were not formatted as human readable in the
|
||||
group_vars. It was all just one long line. This made manual review and
|
||||
debugging more difficult. They are now formatted in a human readable
|
||||
format.
|
@ -2,5 +2,6 @@ Compute_pre_deployments:
|
||||
- ComputeHostEntryDeployment
|
||||
- NetworkDeployment
|
||||
- MyExtraConfigPost
|
||||
- AnsibleDeployment
|
||||
|
||||
Compute_post_deployments: []
|
||||
|
@ -52,6 +52,10 @@ deployments:
|
||||
deployment: 5096a321-64f9-4f07-a74c-53f2b029e62e
|
||||
config: 9ccb2f66-7cd8-4e3e-a034-4c1cfafd037e
|
||||
name: MyExtraConfigPost
|
||||
- server: 169b46f8-1965-4d90-a7de-f36fb4a830fe
|
||||
deployment: 05c94b5d-59ad-484e-b120-e271c2e100ed
|
||||
config: 391263ba-3d06-43b6-a47e-481808aaff20
|
||||
name: AnsibleDeployment
|
||||
|
||||
configs:
|
||||
50fcb6ee-4ff2-4318-b734-d3a7b45a8d6d:
|
||||
@ -98,6 +102,16 @@ configs:
|
||||
echo "An ExtraConfigPost script"
|
||||
outputs: []
|
||||
group: script
|
||||
391263ba-3d06-43b6-a47e-481808aaff20:
|
||||
id: 391263ba-3d06-43b6-a47e-481808aaff20
|
||||
group: ansible
|
||||
outputs: []
|
||||
config: |
|
||||
tasks:
|
||||
- name: An Ansible task
|
||||
copy:
|
||||
content: "{{ some_hostvar | to_json }}"
|
||||
dest: /some/path
|
||||
|
||||
servers:
|
||||
- physical_resource_id: 00b3a5e1-5e8e-4b55-878b-2fa2271f15ad
|
||||
|
@ -52,3 +52,23 @@ MyExtraConfigPost:
|
||||
options: None
|
||||
outputs:
|
||||
|
||||
AnsibleDeployment:
|
||||
id: 391263ba-3d06-43b6-a47e-481808aaff20
|
||||
creation_time: "None"
|
||||
deployment_name: AnsibleDeployment
|
||||
name: None
|
||||
options: None
|
||||
group: ansible
|
||||
inputs:
|
||||
- name: deploy_server_id
|
||||
description: None
|
||||
type: None
|
||||
value: |-
|
||||
169b46f8-1965-4d90-a7de-f36fb4a830fe
|
||||
outputs:
|
||||
config: |
|
||||
tasks:
|
||||
- name: An Ansible task
|
||||
copy:
|
||||
content: "{{ some_hostvar | to_json }}"
|
||||
dest: /some/path
|
||||
|
@ -270,8 +270,25 @@ class Config(object):
|
||||
group_var_server_template = env.get_template('group_var_server.j2')
|
||||
|
||||
for d in deployments:
|
||||
if isinstance(d['config'], dict):
|
||||
d['config'] = json.dumps(d['config'])
|
||||
|
||||
# See if the config can be loaded as a JSON data structure
|
||||
# In some cases, it may already be JSON (hiera), or it may just
|
||||
# be a string (script). In those cases, just use the value
|
||||
# as-is.
|
||||
try:
|
||||
data = json.loads(d['config'])
|
||||
except Exception:
|
||||
data = d['config']
|
||||
|
||||
# If the value is not a string already, pretty print it as a
|
||||
# string so it's rendered in a readable format.
|
||||
if not isinstance(data, six.text_type):
|
||||
data = json.dumps(data, indent=2)
|
||||
|
||||
d['config'] = data
|
||||
|
||||
# The hiera Heat hook expects an actual dict for the config
|
||||
# value, not a scalar. All other hooks expect a scalar.
|
||||
if d['group'] == 'hiera':
|
||||
d['scalar'] = False
|
||||
else:
|
||||
|
Loading…
x
Reference in New Issue
Block a user