Handle includes which may have been created in the flow of the playbook

Since 2.0 made all includes dynamic, it is now possible to create and
include a file in the course of executing a playbook. However, with the
introduction of implicit static includes this can cause problems if an
include is thought to be static but does not yet exist. For now, we're
handling missing implicit static includes as a potential dynamic include
but also adding a deprecation message to show includes like this will
need to be marked as `static: no` in the future.

Fixes #15342
pull/15392/head
James Cammarata 9 years ago
parent 7290b6282d
commit 8ef564176b

@ -22,7 +22,7 @@ import os
from ansible import constants as C from ansible import constants as C
from ansible.compat.six import string_types from ansible.compat.six import string_types
from ansible.errors import AnsibleParserError, AnsibleUndefinedVariable from ansible.errors import AnsibleParserError, AnsibleUndefinedVariable, AnsibleFileNotFound
from ansible.parsing.yaml.objects import AnsibleBaseYAMLObject, AnsibleSequence from ansible.parsing.yaml.objects import AnsibleBaseYAMLObject, AnsibleSequence
try: try:
@ -166,11 +166,27 @@ def load_list_of_tasks(ds, play, block=None, role=None, task_include=None, use_h
else: else:
include_file = loader.path_dwim(include_target) include_file = loader.path_dwim(include_target)
try:
data = loader.load_from_file(include_file) data = loader.load_from_file(include_file)
if data is None: if data is None:
return [] return []
elif not isinstance(data, list): elif not isinstance(data, list):
raise AnsibleError("included task files must contain a list of tasks", obj=data) raise AnsibleError("included task files must contain a list of tasks", obj=data)
except AnsibleFileNotFound as e:
if t.static or \
C.DEFAULT_TASK_INCLUDES_STATIC or \
C.DEFAULT_HANDLER_INCLUDES_STATIC and use_handlers:
raise
display.deprecated(
"Included file '%s' not found, however since this include is not " \
"explicitly marked as 'static: yes', we will try and include it dynamically " \
"later. In the future, this will be an error unless 'static: no' is used " \
"on the include task. If you do not want missing includes to be considered " \
"dynamic, use 'static: yes' on the include or set the global ansible.cfg " \
"options to make all inclues static for tasks and/or handlers" % include_file,
)
task_list.append(t)
continue
included_blocks = load_list_of_blocks( included_blocks = load_list_of_blocks(
data, data,

Loading…
Cancel
Save