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

Make sure set_fact variables go into VARS_CACHE

Fixes #8758
This commit is contained in:
James Cammarata 2014-09-03 09:39:50 -05:00
parent 893f15b30b
commit 14b8e2cf01
2 changed files with 21 additions and 3 deletions

View file

@ -487,11 +487,20 @@ class PlayBook(object):
def _register_play_vars(host, result):
# when 'register' is used, persist the result in the vars cache
# rather than the setup cache - vars should be transient between playbook executions
# rather than the setup cache - vars should be transient between
# playbook executions
if 'stdout' in result and 'stdout_lines' not in result:
result['stdout_lines'] = result['stdout'].splitlines()
utils.update_hash(self.VARS_CACHE, host, {task.register: result})
def _save_play_facts(host, facts):
# saves play facts in SETUP_CACHE, unless the module executed was
# set_fact, in which case we add them to the VARS_CACHE
if task.module_name == 'set_fact':
utils.update_hash(self.VARS_CACHE, host, facts)
else:
utils.update_hash(self.SETUP_CACHE, host, facts)
# add facts to the global setup cache
for host, result in contacted.iteritems():
if 'results' in result:
@ -500,11 +509,13 @@ class PlayBook(object):
for res in result['results']:
if type(res) == dict:
facts = res.get('ansible_facts', {})
utils.update_hash(self.SETUP_CACHE, host, facts)
_save_play_facts(host, facts)
else:
# when facts are returned, persist them in the setup cache
facts = result.get('ansible_facts', {})
utils.update_hash(self.SETUP_CACHE, host, facts)
_save_play_facts(host, facts)
# if requested, save the result into the registered variable name
if task.register:
_register_play_vars(host, result)

View file

@ -9,13 +9,20 @@
roles:
- { role: test_var_precedence, param_var: "param_var" }
tasks:
- name: register a result
command: echo 'BAD!'
register: registered_var
- name: use set_fact to override the registered_var
set_fact: registered_var="this is from set_fact"
- debug: var=extra_var
- debug: var=vars_var
- debug: var=vars_files_var
- debug: var=vars_files_var_role
- debug: var=registered_var
- assert:
that:
- 'extra_var == "extra_var"'
- 'vars_var == "vars_var"'
- 'vars_files_var == "vars_files_var"'
- 'vars_files_var_role == "vars_files_var_role3"'
- 'registered_var == "this is from set_fact"'