From 7589d496fc719c13945262d3a231260fa11f0d17 Mon Sep 17 00:00:00 2001 From: Brian Coca Date: Mon, 4 Feb 2019 17:16:32 -0500 Subject: [PATCH] remove default from delegate_facts to inherit (#45492) (#51553) * remove default from delegate_facts to inherit (#45492) * remove default from delegate_facts to inherit fixes #45456 * test delegate_facts * added note about inheritance and defaults * yamllint (cherry picked from commit 8743e6ae2ee7aa3ae94038554110a9255f5d8fd8) * added changelog --- changelogs/fragments/delegate_facts_fix.yaml | 2 ++ lib/ansible/playbook/block.py | 2 +- lib/ansible/playbook/role/__init__.py | 2 +- lib/ansible/playbook/task.py | 2 +- .../delegate_to/delegate_facts_block.yml | 25 +++++++++++++++++++ test/integration/targets/delegate_to/runme.sh | 2 ++ 6 files changed, 32 insertions(+), 3 deletions(-) create mode 100644 changelogs/fragments/delegate_facts_fix.yaml create mode 100644 test/integration/targets/delegate_to/delegate_facts_block.yml diff --git a/changelogs/fragments/delegate_facts_fix.yaml b/changelogs/fragments/delegate_facts_fix.yaml new file mode 100644 index 00000000000..a44a3957728 --- /dev/null +++ b/changelogs/fragments/delegate_facts_fix.yaml @@ -0,0 +1,2 @@ +bugfixes: +- delegate_facts - fix to work properly under block and include_role (https://github.com/ansible/ansible/pull/51553) diff --git a/lib/ansible/playbook/block.py b/lib/ansible/playbook/block.py index 18b89ca3a8d..50483a9a486 100644 --- a/lib/ansible/playbook/block.py +++ b/lib/ansible/playbook/block.py @@ -38,7 +38,7 @@ class Block(Base, Become, Conditional, Taggable): # other fields _delegate_to = FieldAttribute(isa='string') - _delegate_facts = FieldAttribute(isa='bool', default=False) + _delegate_facts = FieldAttribute(isa='bool') # for future consideration? this would be functionally # similar to the 'else' clause for exceptions diff --git a/lib/ansible/playbook/role/__init__.py b/lib/ansible/playbook/role/__init__.py index 94fba1c2e1a..32b3b084c0d 100644 --- a/lib/ansible/playbook/role/__init__.py +++ b/lib/ansible/playbook/role/__init__.py @@ -94,7 +94,7 @@ def hash_params(params): class Role(Base, Become, Conditional, Taggable): _delegate_to = FieldAttribute(isa='string') - _delegate_facts = FieldAttribute(isa='bool', default=False) + _delegate_facts = FieldAttribute(isa='bool') def __init__(self, play=None, from_files=None, from_include=False): self._role_name = None diff --git a/lib/ansible/playbook/task.py b/lib/ansible/playbook/task.py index 57a96923365..9f715c43ad0 100644 --- a/lib/ansible/playbook/task.py +++ b/lib/ansible/playbook/task.py @@ -73,7 +73,7 @@ class Task(Base, Conditional, Taggable, Become): _changed_when = FieldAttribute(isa='list', default=list) _delay = FieldAttribute(isa='int', default=5) _delegate_to = FieldAttribute(isa='string') - _delegate_facts = FieldAttribute(isa='bool', default=False) + _delegate_facts = FieldAttribute(isa='bool') _failed_when = FieldAttribute(isa='list', default=list) _loop = FieldAttribute() _loop_control = FieldAttribute(isa='class', class_type=LoopControl, inherit=False) diff --git a/test/integration/targets/delegate_to/delegate_facts_block.yml b/test/integration/targets/delegate_to/delegate_facts_block.yml new file mode 100644 index 00000000000..2edfeb42578 --- /dev/null +++ b/test/integration/targets/delegate_to/delegate_facts_block.yml @@ -0,0 +1,25 @@ +- hosts: testhost + gather_facts: false + tasks: + - name: set var to delegated host directly + set_fact: qq1=333 + delegate_facts: true + delegate_to: localhost + + - name: ensure qq1 exists in localhost but not in testhost + assert: + that: + - qq1 is undefined + - "'qq1' in hostvars['localhost']" + + - name: set var to delegated host via inheritance + block: + - set_fact: qq2=333 + delegate_facts: true + delegate_to: localhost + + - name: ensure qq2 exists in localhost but not in testhost + assert: + that: + - qq2 is undefined + - "'qq2' in hostvars['localhost']" diff --git a/test/integration/targets/delegate_to/runme.sh b/test/integration/targets/delegate_to/runme.sh index 4c067a6771e..217aee58c23 100755 --- a/test/integration/targets/delegate_to/runme.sh +++ b/test/integration/targets/delegate_to/runme.sh @@ -12,3 +12,5 @@ ansible-playbook test_delegate_to_loop_randomness.yml -v "$@" ansible-playbook delegate_and_nolog.yml -i inventory -v "$@" ansible-playbook test_delegate_to_loop_caching.yml -i inventory -v "$@" + +ansible-playbook delegate_facts_block.yml -i inventory -v "$@"