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
pull/46782/merge
Brian Coca 6 years ago committed by ansibot
parent 58aaf53271
commit 8743e6ae2e

@ -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

@ -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

@ -66,6 +66,10 @@ class Task(Base, Conditional, Taggable, Become):
# will be used if defined
# might be possible to define others
# NOTE: ONLY set defaults on task attributes that are not inheritable,
# inheritance is only triggered if the 'current value' is None,
# default can be set at play/top level object and inheritance will take it's course.
_args = FieldAttribute(isa='dict', default=dict())
_action = FieldAttribute(isa='string')
@ -73,7 +77,7 @@ class Task(Base, Conditional, Taggable, Become):
_changed_when = FieldAttribute(isa='list', default=[])
_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=[])
_loop = FieldAttribute()
_loop_control = FieldAttribute(isa='class', class_type=LoopControl, inherit=False)

@ -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']"

@ -10,3 +10,5 @@ ansible-playbook test_loop_control.yml -v "$@"
ansible-playbook test_delegate_to_loop_randomness.yml -v "$@"
ansible-playbook delegate_and_nolog.yml -v "$@"
ansible-playbook delegate_facts_block.yml -v "$@"

Loading…
Cancel
Save