diff options
Diffstat (limited to 'lib/ansible/playbook/helpers.py')
-rw-r--r-- | lib/ansible/playbook/helpers.py | 36 |
1 files changed, 30 insertions, 6 deletions
diff --git a/lib/ansible/playbook/helpers.py b/lib/ansible/playbook/helpers.py index 903dcdf4..ff5042a7 100644 --- a/lib/ansible/playbook/helpers.py +++ b/lib/ansible/playbook/helpers.py @@ -21,8 +21,9 @@ __metaclass__ = type import os from ansible import constants as C -from ansible.errors import AnsibleParserError, AnsibleUndefinedVariable, AnsibleAssertionError -from ansible.module_utils.common.text.converters import to_native +from ansible.errors import AnsibleParserError, AnsibleUndefinedVariable, AnsibleFileNotFound, AnsibleAssertionError +from ansible.module_utils._text import to_native +from ansible.module_utils.six import string_types from ansible.parsing.mod_args import ModuleArgsParser from ansible.utils.display import Display @@ -150,9 +151,23 @@ def load_list_of_tasks(ds, play, block=None, role=None, task_include=None, use_h templar = Templar(loader=loader, variables=all_vars) # check to see if this include is dynamic or static: - if action in C._ACTION_IMPORT_TASKS: + # 1. the user has set the 'static' option to false or true + # 2. one of the appropriate config options was set + if action in C._ACTION_INCLUDE_TASKS: + is_static = False + elif action in C._ACTION_IMPORT_TASKS: + is_static = True + else: + include_link = get_versioned_doclink('user_guide/playbooks_reuse_includes.html') + display.deprecated('"include" is deprecated, use include_tasks/import_tasks instead. See %s for details' % include_link, "2.16") + is_static = not templar.is_template(t.args['_raw_params']) and t.all_parents_static() and not t.loop + + if is_static: if t.loop is not None: - raise AnsibleParserError("You cannot use loops on 'import_tasks' statements. You should use 'include_tasks' instead.", obj=task_ds) + if action in C._ACTION_IMPORT_TASKS: + raise AnsibleParserError("You cannot use loops on 'import_tasks' statements. You should use 'include_tasks' instead.", obj=task_ds) + else: + raise AnsibleParserError("You cannot use 'static' on an include with a loop", obj=task_ds) # we set a flag to indicate this include was static t.statically_loaded = True @@ -274,9 +289,18 @@ def load_list_of_tasks(ds, play, block=None, role=None, task_include=None, use_h loader=loader, ) + # 1. the user has set the 'static' option to false or true + # 2. one of the appropriate config options was set + is_static = False if action in C._ACTION_IMPORT_ROLE: + is_static = True + + if is_static: if ir.loop is not None: - raise AnsibleParserError("You cannot use loops on 'import_role' statements. You should use 'include_role' instead.", obj=task_ds) + if action in C._ACTION_IMPORT_ROLE: + raise AnsibleParserError("You cannot use loops on 'import_role' statements. You should use 'include_role' instead.", obj=task_ds) + else: + raise AnsibleParserError("You cannot use 'static' on an include_role with a loop", obj=task_ds) # we set a flag to indicate this include was static ir.statically_loaded = True @@ -288,7 +312,7 @@ def load_list_of_tasks(ds, play, block=None, role=None, task_include=None, use_h ir._role_name = templar.template(ir._role_name) # uses compiled list from object - blocks, dummy = ir.get_block_list(variable_manager=variable_manager, loader=loader) + blocks, _ = ir.get_block_list(variable_manager=variable_manager, loader=loader) task_list.extend(blocks) else: # passes task object itself for latter generation of list |