* 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 8743e6ae2e
)
* added changelog
This commit is contained in:
parent
bdf7f42b7c
commit
7589d496fc
6 changed files with 32 additions and 3 deletions
2
changelogs/fragments/delegate_facts_fix.yaml
Normal file
2
changelogs/fragments/delegate_facts_fix.yaml
Normal file
|
@ -0,0 +1,2 @@
|
||||||
|
bugfixes:
|
||||||
|
- delegate_facts - fix to work properly under block and include_role (https://github.com/ansible/ansible/pull/51553)
|
|
@ -38,7 +38,7 @@ class Block(Base, Become, Conditional, Taggable):
|
||||||
|
|
||||||
# other fields
|
# other fields
|
||||||
_delegate_to = FieldAttribute(isa='string')
|
_delegate_to = FieldAttribute(isa='string')
|
||||||
_delegate_facts = FieldAttribute(isa='bool', default=False)
|
_delegate_facts = FieldAttribute(isa='bool')
|
||||||
|
|
||||||
# for future consideration? this would be functionally
|
# for future consideration? this would be functionally
|
||||||
# similar to the 'else' clause for exceptions
|
# similar to the 'else' clause for exceptions
|
||||||
|
|
|
@ -94,7 +94,7 @@ def hash_params(params):
|
||||||
class Role(Base, Become, Conditional, Taggable):
|
class Role(Base, Become, Conditional, Taggable):
|
||||||
|
|
||||||
_delegate_to = FieldAttribute(isa='string')
|
_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):
|
def __init__(self, play=None, from_files=None, from_include=False):
|
||||||
self._role_name = None
|
self._role_name = None
|
||||||
|
|
|
@ -73,7 +73,7 @@ class Task(Base, Conditional, Taggable, Become):
|
||||||
_changed_when = FieldAttribute(isa='list', default=list)
|
_changed_when = FieldAttribute(isa='list', default=list)
|
||||||
_delay = FieldAttribute(isa='int', default=5)
|
_delay = FieldAttribute(isa='int', default=5)
|
||||||
_delegate_to = FieldAttribute(isa='string')
|
_delegate_to = FieldAttribute(isa='string')
|
||||||
_delegate_facts = FieldAttribute(isa='bool', default=False)
|
_delegate_facts = FieldAttribute(isa='bool')
|
||||||
_failed_when = FieldAttribute(isa='list', default=list)
|
_failed_when = FieldAttribute(isa='list', default=list)
|
||||||
_loop = FieldAttribute()
|
_loop = FieldAttribute()
|
||||||
_loop_control = FieldAttribute(isa='class', class_type=LoopControl, inherit=False)
|
_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']"
|
|
@ -12,3 +12,5 @@ ansible-playbook test_delegate_to_loop_randomness.yml -v "$@"
|
||||||
ansible-playbook delegate_and_nolog.yml -i inventory -v "$@"
|
ansible-playbook delegate_and_nolog.yml -i inventory -v "$@"
|
||||||
|
|
||||||
ansible-playbook test_delegate_to_loop_caching.yml -i inventory -v "$@"
|
ansible-playbook test_delegate_to_loop_caching.yml -i inventory -v "$@"
|
||||||
|
|
||||||
|
ansible-playbook delegate_facts_block.yml -i inventory -v "$@"
|
||||||
|
|
Loading…
Reference in a new issue