a )ghA@sddlmZmZmZeZddlZddlmZ ddl m Z m Z m Z mZddlmZddlmZddlmZddlmZeZdd d Zdd d ZdddZdS))absolute_importdivisionprint_functionN) constants)AnsibleParserErrorAnsibleUndefinedVariableAnsibleFileNotFoundAnsibleAssertionError) to_native) string_types)ModuleArgsParser)DisplayFcCsddlm}t|ttdfs2td|t|fg} |rttt|} | D]} || } g} | dur| | s| | | d7} t | dz || } Wq^t yd} Yq^0q^| | fD](}|r| |j ||||||||dqqN| S)z Given a list of mixed task/block data (parsed from YAML), return a list of Block() objects, where implicit blocks are created for each bare Task. rBlockNz%%s should be a list or None but is %splay parent_blockrole task_include use_handlersvariable_managerloader)ansible.playbook.blockr isinstancelisttyper iterrangelenZis_blockappendnext IndexErrorload)dsrrrrrrrrZ block_listcountiZblock_dsZimplicit_blocksbr(|d}t!"d|d|#|j$d o|%o|j& }|r|j&dur0|tj vr$td|dn td|dd|_'|}d}d}d} |rPd} |durxt|| sp|j(}qPzt)j*+|,|j$-d}!WnLt.y}z2|j'std |j$-d|d|d!WYd}~n d}~00|dur|!}nt)j*/|st)j*0|!|}|,|j$d}"|j1rDt)j*0|j1j2| |}#|3|#| |"}$n|3|4||"}$t)j*5|$rnd}qxn|j(}qP|sz|,|j$d}"Wn@t.y}z&td"|j$d|d|d!WYd}~n d}~00|j1r|3|j1j2| |"}$n |6|"}$|7|$}%|%st!8d#|$qnt|%ts4td$|%dt!9d%|$|j:dd&}&||&_(t;|%|d|&||||d'}'|&j|(|)_<q~|r|'D]})|?|)j@qn |?|'nd|_A||q|tjBvr|rtd(|d)|d| j|||d||d}*d}|tjCvr*d}|r|*j&durb|tjCvrVtd*|dn td+|dd|*_'|j||*d}|||d}|*jD|d,|,|*jE|*_E|*jF||d-\}+},|?|+n ||*q|r| j||||||d}n| j||||||d}||q|S).zw Given a list of task datastructures (parsed from YAML), return a list of Task() or TaskInclude() objects. rr)Handler)Task) TaskInclude) IncludeRole)HandlerTaskInclude)Templar)get_versioned_doclinkz)The ds (%s) should be a list but was a %sz)The ds (%s) should be a dict but was a %sblockz,Using a block as a handler is not supported.)objrT)Zskip_action_validation)r3orig_excN)r2rrrr)rZtask)rZ variablesFz(user_guide/playbooks_reuse_includes.htmlzS"include" is deprecated, use include_tasks/import_tasks instead. See %s for detailsz2.16Z _raw_paramszZYou cannot use loops on 'import_tasks' statements. You should use 'include_tasks' instead.z1You cannot use 'static' on an include with a loopZtaskshandlerszError when evaluating variable in dynamic parent include path: %s. When using static imports, the parent dynamic include cannot utilize host facts or variables from inventory)r3Zsuppress_extended_errorr4a'Error when evaluating variable in import path: %s. When using static imports, ensure that any variables used in their names are defined in vars/vars_files or extra-vars passed in from the command line. Static imports cannot use variables from facts or inventory sources like group or host vars.z,file %s is empty and had no tasks to includez0included task files must contain a list of taskszstatically imported: %s)Zexclude_parent)rrrrrrrzUsing 'z ' as a handler is not supported.zXYou cannot use loops on 'import_role' statements. You should use 'include_role' instead.z6You cannot use 'static' on an include_role with a loop)templar)rr)GrrZansible.playbook.handlerr+Zansible.playbook.taskr,Zansible.playbook.task_includer-Zansible.playbook.role_includer.Z%ansible.playbook.handler_task_includer/Zansible.templater0Zansible.utils.plugin_docsr1rrr rdictrr#r r parser3r CZ _ACTION_ALL_INCLUDE_IMPORT_TASKSZget_varsZ_ACTION_INCLUDE_TASKSZ_ACTION_IMPORT_TASKSdisplayZ deprecatedZ is_templateargsZall_parents_staticZloopZstatically_loadedZ_parentospathdirnametemplategetrisabsjoinZ_roleZ _role_pathZpath_dwim_relativeZ get_basedirexistsZ path_dwimZload_from_fileZwarningZvvcopyr*tagssetunionextendr2 is_staticZ'_ACTION_ALL_PROPER_INCLUDE_IMPORT_ROLESZ_ACTION_IMPORT_ROLEZ post_validateZ _role_nameZget_block_list)-r$rr2rrrrrrr+r,r-r.r/r0r1Z task_listZtask_dstZ args_parseractionr;Z delegate_toeZ include_classZall_varsr6rIZ include_linkZparent_includeZcumulative_pathfoundZsubdirZparent_include_dirZinclude_targetZ new_basedirZ include_filedataZti_copyZincluded_blocksrEr'ZirZblocks_r(r(r)load_list_of_tasksTsZ             (     &                           rPc Cs\ddlm}t|ts*td|t|fg}|D]$}|j||||||d} || q2|S)a Loads and returns a list of RoleInclude objects from the ds list of role definitions :param ds: list of roles to load :param play: calling Play object :param current_role_path: path of the owning role, if any :param variable_manager: varmgr to use for templating :param loader: loader to use for DS parsing/services :param collection_search_list: list of collections to search for unqualified role names :return: r) RoleIncludez%ds (%s) should be a list but was a %s)rcurrent_role_pathrrZcollection_list)Zansible.playbook.role.includerQrrr rr#r ) r$rrRrrZcollection_search_listrQZrolesZrole_defr&r(r(r)load_list_of_rolesKs    rS)NNNFNN)NNNFNN)NNNN)Z __future__rrrrZ __metaclass__r<Zansiblerr9Zansible.errorsrrrr Zansible.module_utils._textr Zansible.module_utils.sixr Zansible.parsing.mod_argsr Zansible.utils.displayr r:r*rPrSr(r(r(r)s      3 x