From 0c40c6c23c3253f7de8d83f03775b1a8aa0dc2c4 Mon Sep 17 00:00:00 2001 From: James Cammarata Date: Fri, 3 Oct 2014 13:30:47 -0500 Subject: [PATCH] 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 --- lib/ansible/playbook/play.py | 3 ++- .../test_var_precedence_dep/defaults/main.yml | 5 +++++ .../roles/test_var_precedence_dep/tasks/main.yml | 14 ++++++++++++++ .../roles/test_var_precedence_dep/vars/main.yml | 4 ++++ .../roles/test_var_precedence_role1/meta/main.yml | 2 ++ 5 files changed, 27 insertions(+), 1 deletion(-) create mode 100644 test/integration/roles/test_var_precedence_dep/defaults/main.yml create mode 100644 test/integration/roles/test_var_precedence_dep/tasks/main.yml create mode 100644 test/integration/roles/test_var_precedence_dep/vars/main.yml create mode 100644 test/integration/roles/test_var_precedence_role1/meta/main.yml diff --git a/lib/ansible/playbook/play.py b/lib/ansible/playbook/play.py index ad57ebd9df3..ca53bc029eb 100644 --- a/lib/ansible/playbook/play.py +++ b/lib/ansible/playbook/play.py @@ -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): diff --git a/test/integration/roles/test_var_precedence_dep/defaults/main.yml b/test/integration/roles/test_var_precedence_dep/defaults/main.yml new file mode 100644 index 00000000000..dda4224c35e --- /dev/null +++ b/test/integration/roles/test_var_precedence_dep/defaults/main.yml @@ -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" diff --git a/test/integration/roles/test_var_precedence_dep/tasks/main.yml b/test/integration/roles/test_var_precedence_dep/tasks/main.yml new file mode 100644 index 00000000000..2f8e17096bc --- /dev/null +++ b/test/integration/roles/test_var_precedence_dep/tasks/main.yml @@ -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"' diff --git a/test/integration/roles/test_var_precedence_dep/vars/main.yml b/test/integration/roles/test_var_precedence_dep/vars/main.yml new file mode 100644 index 00000000000..a69efad537c --- /dev/null +++ b/test/integration/roles/test_var_precedence_dep/vars/main.yml @@ -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" diff --git a/test/integration/roles/test_var_precedence_role1/meta/main.yml b/test/integration/roles/test_var_precedence_role1/meta/main.yml new file mode 100644 index 00000000000..c8b410b59c1 --- /dev/null +++ b/test/integration/roles/test_var_precedence_role1/meta/main.yml @@ -0,0 +1,2 @@ +dependencies: + - test_var_precedence_dep