|
|
@ -487,11 +487,20 @@ class PlayBook(object):
|
|
|
|
|
|
|
|
|
|
|
|
def _register_play_vars(host, result):
|
|
|
|
def _register_play_vars(host, result):
|
|
|
|
# when 'register' is used, persist the result in the vars cache
|
|
|
|
# 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:
|
|
|
|
if 'stdout' in result and 'stdout_lines' not in result:
|
|
|
|
result['stdout_lines'] = result['stdout'].splitlines()
|
|
|
|
result['stdout_lines'] = result['stdout'].splitlines()
|
|
|
|
utils.update_hash(self.VARS_CACHE, host, {task.register: result})
|
|
|
|
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
|
|
|
|
# add facts to the global setup cache
|
|
|
|
for host, result in contacted.iteritems():
|
|
|
|
for host, result in contacted.iteritems():
|
|
|
|
if 'results' in result:
|
|
|
|
if 'results' in result:
|
|
|
@ -500,11 +509,13 @@ class PlayBook(object):
|
|
|
|
for res in result['results']:
|
|
|
|
for res in result['results']:
|
|
|
|
if type(res) == dict:
|
|
|
|
if type(res) == dict:
|
|
|
|
facts = res.get('ansible_facts', {})
|
|
|
|
facts = res.get('ansible_facts', {})
|
|
|
|
utils.update_hash(self.SETUP_CACHE, host, facts)
|
|
|
|
_save_play_facts(host, facts)
|
|
|
|
else:
|
|
|
|
else:
|
|
|
|
# when facts are returned, persist them in the setup cache
|
|
|
|
# when facts are returned, persist them in the setup cache
|
|
|
|
facts = result.get('ansible_facts', {})
|
|
|
|
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:
|
|
|
|
if task.register:
|
|
|
|
_register_play_vars(host, result)
|
|
|
|
_register_play_vars(host, result)
|
|
|
|
|
|
|
|
|
|
|
|