VariableManager - add the 'vars' key before getting delegated variables (#71214)

* VariableManager - add the 'vars' key before getting delegated variables
pull/25260/head
Sloane Hertel 4 years ago committed by GitHub
parent fb03ac7019
commit cceba07114
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -0,0 +1,2 @@
bugfixes:
- VariableManager - Add the 'vars' key before getting delegated variables (https://github.com/ansible/ansible/issues/71092).

@ -426,16 +426,16 @@ class VariableManager:
if task:
all_vars['environment'] = task.environment
# if we have a task and we're delegating to another host, figure out the
# variables for that host now so we don't have to rely on hostvars later
if task and task.delegate_to is not None and include_delegate_to:
all_vars['ansible_delegated_vars'], all_vars['_ansible_loop_cache'] = self._get_delegated_vars(play, task, all_vars)
# 'vars' magic var
if task or play:
# has to be copy, otherwise recursive ref
all_vars['vars'] = all_vars.copy()
# if we have a task and we're delegating to another host, figure out the
# variables for that host now so we don't have to rely on hostvars later
if task and task.delegate_to is not None and include_delegate_to:
all_vars['ansible_delegated_vars'], all_vars['_ansible_loop_cache'] = self._get_delegated_vars(play, task, all_vars)
display.debug("done with get_vars()")
if C.DEFAULT_DEBUG:
# Use VarsWithSources wrapper class to display var sources

@ -0,0 +1,16 @@
---
- name: though we test for 'vars' this is only for backwards compatibility and the 'vars' variable will be deprecated and removed in the future
hosts: localhost
gather_facts: no
tasks:
- add_host:
name: host1
ansible_connection: local
- hosts: localhost
gather_facts: no
vars:
server_name: host1
tasks:
- command: echo should delegate to host1 with local connection
delegate_to: "{{ vars['server_name'] }}"

@ -71,3 +71,5 @@ ln -s python secondpython
)
ansible-playbook verify_interpreter.yml -i inventory_interpreters -v "$@"
ansible-playbook discovery_applied.yml -i inventory -v "$@"
ansible-playbook resolve_vars.yml -i inventory -v "$@"

Loading…
Cancel
Save