mirror of
https://github.com/ansible-collections/community.general.git
synced 2025-04-25 20:01:25 -07:00
Forward conditionals onto included plays when conditional eval errors
When using a playbook-level include, we now catch any errors raised during the conditional evaluation step and set a flag to indicate we need to pass those conditionals on to the included play (most likely because they contain inventory variables for evaluation). Fixes #14003
This commit is contained in:
parent
c8bbdd6b39
commit
e3a6accc1d
1 changed files with 17 additions and 3 deletions
|
@ -22,7 +22,7 @@ __metaclass__ = type
|
||||||
import os
|
import os
|
||||||
|
|
||||||
from ansible.compat.six import iteritems
|
from ansible.compat.six import iteritems
|
||||||
from ansible.errors import AnsibleParserError
|
from ansible.errors import AnsibleParserError, AnsibleError
|
||||||
from ansible.parsing.splitter import split_args, parse_kv
|
from ansible.parsing.splitter import split_args, parse_kv
|
||||||
from ansible.parsing.yaml.objects import AnsibleBaseYAMLObject, AnsibleMapping
|
from ansible.parsing.yaml.objects import AnsibleBaseYAMLObject, AnsibleMapping
|
||||||
from ansible.playbook.attribute import FieldAttribute
|
from ansible.playbook.attribute import FieldAttribute
|
||||||
|
@ -60,8 +60,15 @@ class PlaybookInclude(Base, Conditional, Taggable):
|
||||||
all_vars.update(variable_manager.get_vars(loader=loader))
|
all_vars.update(variable_manager.get_vars(loader=loader))
|
||||||
|
|
||||||
templar = Templar(loader=loader, variables=all_vars)
|
templar = Templar(loader=loader, variables=all_vars)
|
||||||
if not new_obj.evaluate_conditional(templar=templar, all_vars=all_vars):
|
|
||||||
return None
|
try:
|
||||||
|
forward_conditional = False
|
||||||
|
if not new_obj.evaluate_conditional(templar=templar, all_vars=all_vars):
|
||||||
|
return None
|
||||||
|
except AnsibleError:
|
||||||
|
# conditional evaluation raised an error, so we set a flag to indicate
|
||||||
|
# we need to forward the conditionals on to the included play(s)
|
||||||
|
forward_conditional = True
|
||||||
|
|
||||||
# then we use the object to load a Playbook
|
# then we use the object to load a Playbook
|
||||||
pb = Playbook(loader=loader)
|
pb = Playbook(loader=loader)
|
||||||
|
@ -85,6 +92,13 @@ class PlaybookInclude(Base, Conditional, Taggable):
|
||||||
if entry._included_path is None:
|
if entry._included_path is None:
|
||||||
entry._included_path = os.path.dirname(file_name)
|
entry._included_path = os.path.dirname(file_name)
|
||||||
|
|
||||||
|
# Check to see if we need to forward the conditionals on to the included
|
||||||
|
# plays. If so, we can take a shortcut here and simply prepend them to
|
||||||
|
# those attached to each block (if any)
|
||||||
|
if forward_conditional:
|
||||||
|
for task_block in entry.tasks:
|
||||||
|
task_block.when = self.when[:] + task_block.when
|
||||||
|
|
||||||
return pb
|
return pb
|
||||||
|
|
||||||
def preprocess_data(self, ds):
|
def preprocess_data(self, ds):
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue