From 279543d7c9d1647b0c5d9281da70d279da13ea66 Mon Sep 17 00:00:00 2001 From: Alex Schultz Date: Thu, 1 Nov 2018 15:42:11 -0600 Subject: [PATCH] Use pyyaml to output group vars Because the ansible group vars can be more complex structures than strings and ints, we should use yaml to output the groupvars files. This will allow list or dict values to be correctly represented in the ansible vars files. Change-Id: I79b3e6a5e7acb5f95d65034a2908a005d9a343db Closes-Bug: #1801162 --- tripleo_common/templates/group_var_role.j2 | 3 --- tripleo_common/tests/utils/data/Compute | 2 +- tripleo_common/tests/utils/data/Controller | 2 +- tripleo_common/tests/utils/test_config.py | 8 ++++---- tripleo_common/utils/config.py | 14 ++++++-------- 5 files changed, 12 insertions(+), 17 deletions(-) delete mode 100644 tripleo_common/templates/group_var_role.j2 diff --git a/tripleo_common/templates/group_var_role.j2 b/tripleo_common/templates/group_var_role.j2 deleted file mode 100644 index b8b16f0dc..000000000 --- a/tripleo_common/templates/group_var_role.j2 +++ /dev/null @@ -1,3 +0,0 @@ -{% for k,v in role_group_vars.items() %} -{{ k }}: {{ v }} -{% endfor %} diff --git a/tripleo_common/tests/utils/data/Compute b/tripleo_common/tests/utils/data/Compute index 31d60d7d9..6f1436f77 100644 --- a/tripleo_common/tests/utils/data/Compute +++ b/tripleo_common/tests/utils/data/Compute @@ -1,2 +1,2 @@ max_fail_percentage: 15 -any_errors_fatal: yes +any_errors_fatal: True diff --git a/tripleo_common/tests/utils/data/Controller b/tripleo_common/tests/utils/data/Controller index 31d60d7d9..6f1436f77 100644 --- a/tripleo_common/tests/utils/data/Controller +++ b/tripleo_common/tests/utils/data/Controller @@ -1,2 +1,2 @@ max_fail_percentage: 15 -any_errors_fatal: yes +any_errors_fatal: True diff --git a/tripleo_common/tests/utils/test_config.py b/tripleo_common/tests/utils/test_config.py index 0fe2b1049..cc2528ce4 100644 --- a/tripleo_common/tests/utils/test_config.py +++ b/tripleo_common/tests/utils/test_config.py @@ -279,10 +279,10 @@ class TestConfig(base.TestCase): {'output_key': 'RoleGroupVars', 'output_value': { 'Controller': { - 'any_errors_fatal': 'yes', + 'any_errors_fatal': True, 'max_fail_percentage': 15}, 'Compute': { - 'any_errors_fatal': 'yes', + 'any_errors_fatal': True, 'max_fail_percentage': 15}, }}] deployment_data, configs = \ @@ -615,10 +615,10 @@ class TestConfig(base.TestCase): {'output_key': 'RoleGroupVars', 'output_value': { 'Controller': { - 'any_errors_fatal': 'yes', + 'any_errors_fatal': True, 'max_fail_percentage': 15}, 'Compute': { - 'any_errors_fatal': 'yes', + 'any_errors_fatal': True, 'max_fail_percentage': 15}, }}] deployment_data, configs = \ diff --git a/tripleo_common/utils/config.py b/tripleo_common/utils/config.py index ce51fb50e..3dcf6a3d2 100644 --- a/tripleo_common/utils/config.py +++ b/tripleo_common/utils/config.py @@ -441,14 +441,12 @@ class Config(object): # Render group_vars for role in set(server_roles.values()): group_var_role_path = os.path.join(group_vars_dir, role) - group_var_role_template = env.get_template('group_var_role.j2') - - with open(group_var_role_path, 'w') as f: - template_data = group_var_role_template.render( - role=role, - role_group_vars=role_group_vars[role]) - self.validate_config(template_data, group_var_role_path) - f.write(template_data) + # NOTE(aschultz): we just use yaml.safe_dump for the vars because + # the vars should already bein a hash for for ansible. + # See LP#1801162 for previous issues around using jinja for this + with open(group_var_role_path, 'w') as group_vars_file: + yaml.safe_dump(role_group_vars[role], group_vars_file, + default_flow_style=False) # Render host_vars for server, deployments in server_deployment_names.items():