Clarify clear facts (#50667)

* Revert "avoid x2 setting of set_fact when 'cacheable' (#50564)"

This reverts commit 207848f354.

* clarify clear_facts with set_fact cacheable

 revert previous 'fix' as it will break playbooks by changing precedence
 opted to leave current behaviour but document it on both plugins to mitigate confusion

 fixes #50556

 also fix grammer, add comment, remove unused e
This commit is contained in:
Brian Coca 2019-01-15 15:20:33 -05:00 committed by GitHub
commit 119b65f919
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
6 changed files with 16 additions and 8 deletions

View file

@ -570,10 +570,15 @@ class StrategyBase:
else:
cacheable = result_item.pop('_ansible_facts_cacheable', False)
for target_host in host_list:
if original_task.action == 'set_fact' and not cacheable:
self._variable_manager.set_nonpersistent_facts(target_host, result_item['ansible_facts'].copy())
else:
# so set_fact is a misnomer but 'cacheable = true' was meant to create an 'actual fact'
# to avoid issues with precedence and confusion with set_fact normal operation,
# we set BOTH fact and nonpersistent_facts (aka hostvar)
# when fact is retrieved from cache in subsequent operations it will have the lower precedence,
# but for playbook setting it the 'higher' precedence is kept
if original_task.action != 'set_fact' or cacheable:
self._variable_manager.set_host_facts(target_host, result_item['ansible_facts'].copy())
if original_task.action == 'set_fact':
self._variable_manager.set_nonpersistent_facts(target_host, result_item['ansible_facts'].copy())
if 'ansible_stats' in result_item and 'data' in result_item['ansible_stats'] and result_item['ansible_stats']['data']:
@ -892,7 +897,7 @@ class StrategyBase:
loader=self._loader,
variable_manager=self._variable_manager
)
except AnsibleError as e:
except AnsibleError:
return False
result = True