mirror of
https://github.com/ansible-collections/community.general.git
synced 2025-10-09 09:54:02 -07:00
Fieldattribute inheritance with defaults (#50891)
* Add tests for check_mode at play and task level These test inheritance of check_mode from the various levels (command line, as a play attribute and as a task attribute) so they will be useful for checking that the change to fieldattribute inheritance with defaults works * Add a sentinel object The Sentinel object can be used in place of None when we need to mark an entry as being special (usually used to mark something as not having been set) * Start of using a Sentinel object instead of None. * Handle edge cases around use of Sentinel * _get_parent_attribute needs to deal in Sentinel not None * No need to special case any_errors_fatal in task.py any longer * Handle more edge cases around Sentinel * Use Sentinel instead of None in TaskInclude * Update code to clarify the vars we are copying are class attrs * Add changelog fragment * Use a default of Sentinel for delegate_to, this also allows 'delegate_to: ~' now to unset inherited delegate_to * Explain Sentinel stripping in _extend_value * Fix ModuleArgsParser tests to compare with Sentinel * Fixes for tasks inside of roles inheriting from play * Remove incorrect note. ci_complete * Remove commented code
This commit is contained in:
parent
ad57efff8f
commit
8c08d03989
14 changed files with 213 additions and 59 deletions
|
@ -27,6 +27,7 @@ from ansible.playbook.conditional import Conditional
|
|||
from ansible.playbook.helpers import load_list_of_tasks
|
||||
from ansible.playbook.role import Role
|
||||
from ansible.playbook.taggable import Taggable
|
||||
from ansible.utils.sentinel import Sentinel
|
||||
|
||||
|
||||
class Block(Base, Become, Conditional, Taggable):
|
||||
|
@ -311,51 +312,45 @@ class Block(Base, Become, Conditional, Taggable):
|
|||
else:
|
||||
_parent = self._parent._parent
|
||||
|
||||
if _parent and (value is None or extend):
|
||||
if _parent and (value is Sentinel or extend):
|
||||
try:
|
||||
if getattr(_parent, 'statically_loaded', True):
|
||||
if hasattr(_parent, '_get_parent_attribute'):
|
||||
parent_value = _parent._get_parent_attribute(attr)
|
||||
else:
|
||||
parent_value = _parent._attributes.get(attr, None)
|
||||
parent_value = _parent._attributes.get(attr, Sentinel)
|
||||
if extend:
|
||||
value = self._extend_value(value, parent_value, prepend)
|
||||
else:
|
||||
value = parent_value
|
||||
except AttributeError:
|
||||
pass
|
||||
if self._role and (value is None or extend):
|
||||
if self._role and (value is Sentinel or extend):
|
||||
try:
|
||||
if hasattr(self._role, '_get_parent_attribute'):
|
||||
parent_value = self._role.get_parent_attribute(attr)
|
||||
else:
|
||||
parent_value = self._role._attributes.get(attr, None)
|
||||
parent_value = self._role._attributes.get(attr, Sentinel)
|
||||
if extend:
|
||||
value = self._extend_value(value, parent_value, prepend)
|
||||
else:
|
||||
value = parent_value
|
||||
|
||||
dep_chain = self.get_dep_chain()
|
||||
if dep_chain and (value is None or extend):
|
||||
if dep_chain and (value is Sentinel or extend):
|
||||
dep_chain.reverse()
|
||||
for dep in dep_chain:
|
||||
if hasattr(dep, '_get_parent_attribute'):
|
||||
dep_value = dep._get_parent_attribute(attr)
|
||||
else:
|
||||
dep_value = dep._attributes.get(attr, None)
|
||||
dep_value = dep._attributes.get(attr, Sentinel)
|
||||
if extend:
|
||||
value = self._extend_value(value, dep_value, prepend)
|
||||
else:
|
||||
value = dep_value
|
||||
|
||||
if value is not None and not extend:
|
||||
if value is not Sentinel and not extend:
|
||||
break
|
||||
except AttributeError:
|
||||
pass
|
||||
if self._play and (value is None or extend):
|
||||
if self._play and (value is Sentinel or extend):
|
||||
try:
|
||||
play_value = self._play._attributes.get(attr, None)
|
||||
if play_value is not None:
|
||||
play_value = self._play._attributes.get(attr, Sentinel)
|
||||
if play_value is not Sentinel:
|
||||
if extend:
|
||||
value = self._extend_value(value, play_value, prepend)
|
||||
else:
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue