1
0
Fork 0
mirror of https://github.com/ansible-collections/community.general.git synced 2024-09-14 20:13:21 +02:00

Fix order of resolving dependent role variables from vars files

Also adds a new class to the test_var_precedence test to check for
this type of error in the future.

Fixes #9178
This commit is contained in:
James Cammarata 2014-10-03 13:30:47 -05:00
parent 402d0c37b8
commit 0c40c6c23c
5 changed files with 27 additions and 1 deletions

View file

@ -287,7 +287,8 @@ class Play(object):
if os.path.isfile(vars):
vars_data = utils.parse_yaml_from_file(vars, vault_password=self.vault_password)
if vars_data:
dep_vars = utils.combine_vars(vars_data, dep_vars)
#dep_vars = utils.combine_vars(vars_data, dep_vars)
dep_vars = utils.combine_vars(dep_vars, vars_data)
defaults = self._resolve_main(utils.path_dwim(self.basedir, os.path.join(dep_path, 'defaults')))
dep_defaults_data = {}
if os.path.isfile(defaults):

View file

@ -0,0 +1,5 @@
---
# should be overridden by vars_files in the main play
vars_files_var: "BAD!"
# should be seen in role1 (no override)
defaults_file_var_role1: "defaults_file_var_role1"

View file

@ -0,0 +1,14 @@
- debug: var=extra_var
- debug: var=param_var
- debug: var=vars_var
- debug: var=vars_files_var
- debug: var=vars_files_var_role
- debug: var=defaults_file_var_role1
- assert:
that:
- 'extra_var == "extra_var"'
- 'param_var == "param_var_role1"'
- 'vars_var == "vars_var"'
- 'vars_files_var == "vars_files_var"'
- 'vars_files_var_role == "vars_files_var_dep"'
- 'defaults_file_var_role1 == "defaults_file_var_role1"'

View file

@ -0,0 +1,4 @@
---
# should override the global vars_files_var since it's local to the role
# but will be set to the value in the last role included which defines it
vars_files_var_role: "vars_files_var_dep"

View file

@ -0,0 +1,2 @@
dependencies:
- test_var_precedence_dep