From 8ef564176bfcfaaedeb4bab060a892f19aa7fc10 Mon Sep 17 00:00:00 2001 From: James Cammarata Date: Tue, 12 Apr 2016 09:29:43 -0400 Subject: [PATCH] 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 --- lib/ansible/playbook/helpers.py | 28 ++++++++++++++++++++++------ 1 file changed, 22 insertions(+), 6 deletions(-) diff --git a/lib/ansible/playbook/helpers.py b/lib/ansible/playbook/helpers.py index 0b5491b31c6..608f3ee503b 100644 --- a/lib/ansible/playbook/helpers.py +++ b/lib/ansible/playbook/helpers.py @@ -22,7 +22,7 @@ import os from ansible import constants as C 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 try: @@ -166,11 +166,27 @@ def load_list_of_tasks(ds, play, block=None, role=None, task_include=None, use_h else: include_file = loader.path_dwim(include_target) - data = loader.load_from_file(include_file) - if data is None: - return [] - elif not isinstance(data, list): - raise AnsibleError("included task files must contain a list of tasks", obj=data) + try: + data = loader.load_from_file(include_file) + if data is None: + return [] + elif not isinstance(data, list): + 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( data,