Skip to content

Commit

Permalink
restore role param precedence (ansible#82106)
Browse files Browse the repository at this point in the history
* add test for setfact/param override
  • Loading branch information
bcoca committed Nov 6, 2023
1 parent 5ac6247 commit 20a54eb
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 1 deletion.
2 changes: 2 additions & 0 deletions changelogs/fragments/restore_role_param_precedence.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
bugfixes:
- role params now have higher precedence than host facts again, matching documentation, this had unintentionally changed in 2.15.
4 changes: 3 additions & 1 deletion lib/ansible/vars/manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -406,7 +406,7 @@ def plugins_by_groups():
# vars (which will look at parent blocks/task includes)
if task:
if task._role:
all_vars = _combine_and_track(all_vars, task._role.get_vars(task.get_dep_chain(), include_params=True, only_exports=False),
all_vars = _combine_and_track(all_vars, task._role.get_vars(task.get_dep_chain(), include_params=False, only_exports=False),
"role '%s' all vars" % task._role.name)
all_vars = _combine_and_track(all_vars, task.get_vars(), "task vars")

Expand All @@ -423,6 +423,8 @@ def plugins_by_groups():
# special case for include tasks, where the include params
# may be specified in the vars field for the task, which should
# have higher precedence than the vars/np facts above
if task._role:
all_vars = _combine_and_track(all_vars, task._role.get_role_params(task.get_dep_chain()), "role params")
all_vars = _combine_and_track(all_vars, task.get_include_params(), "include params")

# extra vars
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,10 @@
from_inventory_once_removed: "{{ inven_var | default('BAD!') }}"
vars_files:
- vars/test_var_precedence.yml
pre_tasks:
- name: param vars should also override set_fact
set_fact:
param_var: "BAD!"
roles:
- { role: test_var_precedence, param_var: "param_var" }
tasks:
Expand Down

0 comments on commit 20a54eb

Please sign in to comment.