mirror of
https://github.com/ansible-collections/community.general.git
synced 2025-07-23 05:10:22 -07:00
parent
29a9b8ab7d
commit
66a8864ae9
6 changed files with 31 additions and 20 deletions
|
@ -49,7 +49,7 @@ class Base:
|
|||
|
||||
# vars and flags
|
||||
_vars = FieldAttribute(isa='dict', default=dict())
|
||||
_environment = FieldAttribute(isa='dict', default=dict())
|
||||
_environment = FieldAttribute(isa='list', default=[])
|
||||
_no_log = FieldAttribute(isa='bool', default=False)
|
||||
|
||||
def __init__(self):
|
||||
|
|
|
@ -301,6 +301,18 @@ class Block(Base, Become, Conditional, Taggable):
|
|||
|
||||
return value
|
||||
|
||||
def _get_attr_environment(self):
|
||||
'''
|
||||
Override for the 'tags' getattr fetcher, used from Base.
|
||||
'''
|
||||
environment = self._attributes['tags']
|
||||
if environment is None:
|
||||
environment = dict()
|
||||
|
||||
environment = self._get_parent_attribute('environment', extend=True)
|
||||
|
||||
return environment
|
||||
|
||||
def filter_tagged_tasks(self, play_context, all_vars):
|
||||
'''
|
||||
Creates a new block, with task lists filtered based on the tags contained
|
||||
|
|
|
@ -217,7 +217,6 @@ class PlayContext(Base):
|
|||
|
||||
# non connection related
|
||||
self.no_log = play.no_log
|
||||
self.environment = play.environment
|
||||
|
||||
if play.force_handlers is not None:
|
||||
self.force_handlers = play.force_handlers
|
||||
|
@ -299,7 +298,7 @@ class PlayContext(Base):
|
|||
|
||||
# loop through a subset of attributes on the task object and set
|
||||
# connection fields based on their values
|
||||
for attr in ('connection', 'remote_user', 'become', 'become_user', 'become_pass', 'become_method', 'environment', 'no_log'):
|
||||
for attr in ('connection', 'remote_user', 'become', 'become_user', 'become_pass', 'become_method', 'no_log'):
|
||||
if hasattr(task, attr):
|
||||
attr_val = getattr(task, attr)
|
||||
if attr_val is not None:
|
||||
|
|
|
@ -34,7 +34,6 @@ from ansible.playbook.block import Block
|
|||
from ansible.playbook.conditional import Conditional
|
||||
from ansible.playbook.role import Role
|
||||
from ansible.playbook.taggable import Taggable
|
||||
from ansible.utils.vars import combine_vars
|
||||
|
||||
__all__ = ['Task']
|
||||
|
||||
|
@ -293,25 +292,21 @@ class Task(Base, Conditional, Taggable, Become):
|
|||
if self._task_include:
|
||||
self._task_include.set_loader(loader)
|
||||
|
||||
def _get_parent_attribute(self, attr, extend=False, combine=False):
|
||||
def _get_parent_attribute(self, attr, extend=False):
|
||||
'''
|
||||
Generic logic to get the attribute or parent attribute for a task value.
|
||||
'''
|
||||
value = self._attributes[attr]
|
||||
if self._block and (value is None or extend or combine):
|
||||
if self._block and (value is None or extend):
|
||||
parent_value = getattr(self._block, attr)
|
||||
if extend:
|
||||
value = self._extend_value(value, parent_value)
|
||||
elif combine and isinstance(parent_value, dict) and isinstance(value, dict):
|
||||
value = combine_vars(parent_value, value)
|
||||
else:
|
||||
value = parent_value
|
||||
if self._task_include and (value is None or extend or combine):
|
||||
if self._task_include and (value is None or extend):
|
||||
parent_value = getattr(self._task_include, attr)
|
||||
if extend:
|
||||
value = self._extend_value(value, parent_value)
|
||||
elif combine:
|
||||
value = combine_vars(parent_value, value)
|
||||
else:
|
||||
value = parent_value
|
||||
return value
|
||||
|
@ -324,7 +319,7 @@ class Task(Base, Conditional, Taggable, Become):
|
|||
if environment is None:
|
||||
environment = dict()
|
||||
|
||||
environment = self._get_parent_attribute('environment', combine=True)
|
||||
environment = self._get_parent_attribute('environment', extend=True)
|
||||
|
||||
return environment
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue