Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix debug factsetter #74067

Merged
merged 6 commits into from Mar 31, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 2 additions & 0 deletions changelogs/fragments/debug_dont_set_facts.yml
@@ -0,0 +1,2 @@
bugfixes:
- debug action, prevent setting facts when displaying ansible_facts.
4 changes: 2 additions & 2 deletions lib/ansible/executor/task_executor.py
Expand Up @@ -632,7 +632,7 @@ def _evaluate_failed_when_result(result):
failed_when_result = False
return failed_when_result

if 'ansible_facts' in result:
if 'ansible_facts' in result and self._task.action not in C._ACTION_DEBUG:
if self._task.action in C._ACTION_WITH_CLEAN_FACTS:
vars_copy.update(result['ansible_facts'])
else:
Expand Down Expand Up @@ -704,7 +704,7 @@ def _evaluate_failed_when_result(result):
if self._task.register:
variables[self._task.register] = result = wrap_var(result)

if 'ansible_facts' in result:
if 'ansible_facts' in result and self._task.action not in C._ACTION_DEBUG:
if self._task.action in C._ACTION_WITH_CLEAN_FACTS:
variables.update(result['ansible_facts'])
else:
Expand Down
2 changes: 1 addition & 1 deletion lib/ansible/plugins/strategy/__init__.py
Expand Up @@ -663,7 +663,7 @@ def search_handler_blocks_by_name(handler_name, handler_blocks):
self._add_group(original_host, result_item)
post_process_whens(result_item, original_task, handler_templar)

if 'ansible_facts' in result_item:
if 'ansible_facts' in result_item and original_task.action not in C._ACTION_DEBUG:
# if delegated fact and we are delegating facts, we need to change target host for them
if original_task.delegate_to is not None and original_task.delegate_facts:
host_list = self.get_delegated_hosts(result_item, original_task)
Expand Down
21 changes: 21 additions & 0 deletions test/integration/targets/debug/nosetfacts.yml
@@ -0,0 +1,21 @@
- name: check we dont set facts with debug ansible_facts https://github.com/ansible/ansible/issues/74060
hosts: localhost
gather_facts: false
tasks:
- name: create namespaced non fact
set_fact:
ansible_facts:
nonfact: 1

- name: ensure nonfact does not exist
assert:
that:
- nonfact is not defined

- name: debug ansible_facts to create issue
debug: var=ansible_facts

- name: ensure nonfact STILL does not exist
assert:
that:
- nonfact is not defined
3 changes: 3 additions & 0 deletions test/integration/targets/debug/runme.sh
Expand Up @@ -15,3 +15,6 @@ for i in 1 2 3; do
grep "ok: \[localhost\] => (item=$i)" out
grep "\"item\": $i" out
done

# ensure debug does not set top level vars when looking at ansible_facts
ansible-playbook nosetfacts.yml "$@"