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:
parent
402d0c37b8
commit
0c40c6c23c
5 changed files with 27 additions and 1 deletions
|
@ -287,7 +287,8 @@ class Play(object):
|
||||||
if os.path.isfile(vars):
|
if os.path.isfile(vars):
|
||||||
vars_data = utils.parse_yaml_from_file(vars, vault_password=self.vault_password)
|
vars_data = utils.parse_yaml_from_file(vars, vault_password=self.vault_password)
|
||||||
if vars_data:
|
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')))
|
defaults = self._resolve_main(utils.path_dwim(self.basedir, os.path.join(dep_path, 'defaults')))
|
||||||
dep_defaults_data = {}
|
dep_defaults_data = {}
|
||||||
if os.path.isfile(defaults):
|
if os.path.isfile(defaults):
|
||||||
|
|
|
@ -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"
|
|
@ -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"'
|
|
@ -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"
|
|
@ -0,0 +1,2 @@
|
||||||
|
dependencies:
|
||||||
|
- test_var_precedence_dep
|
Loading…
Reference in a new issue