a )g5@sddlmZmZmZeZddlmZddl m Z m Z m Z ddl mZddlmZddlmZmZddlmZmZddlmZdd lmZdd lmZeejZe ed Z!eed Z"Gd ddZ#dS))absolute_importdivisionprint_functionN)AnsibleParserError AnsibleErrorAnsibleAssertionError) string_types)to_text)parse_kv split_args) module_loader action_loader)Templar)add_internal_fqcns)Sentinel) includeZ include_vars include_tasks include_role import_tasks import_roleZadd_hostZgroup_byZset_factmeta)rrrrrrc@sFeZdZdZdddZddZdddZd d Zd d ZdddZ dS)ModuleArgsParsera? There are several ways a module and argument set can be expressed: # legacy form (for a shell command) - action: shell echo hi # common shorthand for local actions vs delegate_to - local_action: shell echo hi # most commonly: - copy: src=a dest=b # legacy form - action: copy src=a dest=b # complex args form, for passing structured data - copy: src: a dest: b # gross, but technically legal - action: module: copy args: src: a dest: b # Standard YAML form for command-type modules. In this case, the args specified # will act as 'defaults' and will be overridden by any args specified # in one of the other formats (complex args under the action, or # parsed from the k=v string - command: 'pwd' args: chdir: '/tmp' This class has some of the logic to canonicalize these into the form - module: delegate_to: args: Args may also be munged for certain shell command parameters. NcCs|dur in|}t|ts*tdt|||_||_ddlm}ddlm }t |j |_ |j t |j |j ddgt|j |_ d|_dS)Nz3the type of 'task_ds' should be a dict, but is a %sr)Task)Handler local_actionZstatic) isinstancedictrtype_task_ds_collection_listZansible.playbook.taskrZansible.playbook.handlerrsetZ fattributes _task_attrsupdate frozensetresolved_action)selfZtask_dscollection_listrrr'd}ntdt||jd|S)ak deals with fuzziness in new style module invocations accepting key=value pairs and dictionaries, and returns a dictionary of arguments possible example inputs: 'echo hi', 'shell' {'region': 'xyz'}, 'ec2' standardized outputs like: { _raw_params: 'echo hi', _uses_shell: True }  check_rawN'unexpected parameter type in action: %sobj)rrrr:r rrr)r%r<r=r5rCr'r'r(r7s  z*ModuleArgsParser._normalize_new_style_argscCsd}d}t|tr^|}d|vr||d\}}|}|tv}|t||d|d=nDt|tr||\}}|tv}t||d}ntdt ||j d||fS)a\ deals with fuzziness in old-style (action/local_action) module invocations returns tuple of (module_name, dictionary_args) possible example inputs: { 'shell' : 'echo hi' } 'shell echo hi' {'module': 'ec2', 'x': 1 } standardized outputs like: ('ec2', { 'x': 1} ) NmodulerBrDrE) rrcopyr1r:r"r rrrr)r%r<r=r5Z module_argsrCr'r'r(r8s   z*ModuleArgsParser._normalize_old_style_argsFcs.d}d}jdt}t}jdt}djvrTjd}j|||d\}}djvr|durttdjdjdd }d }j|||d\}}tfd d jD}|D]\}} d} d } |tvrd} nD|rd} n:tj |j d} | j st j |j d} | j ot | j} | r|durDtd||fjd| dur^| j r^| j_|}| }j|||d\}}q|dur|rt|d} td| jdntdjdnb|dd d kr$|tvr$tdd} |d}| |r||d<ntd|dtfjd|||fS)z Given a task in one of the supported forms, parses and returns returns the action, arguments, and delegate_to values for the task, dealing with all sorts of levels of fuzziness. N delegate_tor5r=)r=r>rz.action and local_action are mutually exclusiverEr,Z localhostc3s.|]&\}}|jvr|ds||fVqdS)Zwith_N)r!r;).0kvr%r'r( (z)ModuleArgsParser.parse..FT)r&z%conflicting action statements: %s, %srzwcouldn't resolve module/action '{0}'. This often indicates a misspelling, missing collection, or incorrect module path.z"no module/action detected in task.Z _raw_paramsr2r4zSthis task '%s' has extra params, which is only allowed in the following modules: %sz, )rgetrrrAritems BUILTIN_TASKSr Zfind_plugin_with_contextrZresolvedr boolZ redirect_listZ resolved_fqcnr$listkeysformatRAW_PARAM_MODULESrr9r6r/)r%Zskip_action_validationr<r=rIr5r>Z non_task_dsitemvaluecontextZis_action_candidateZ bad_actionr?Z raw_paramsr'rMr(parsesp         zModuleArgsParser.parse)NN)NN)F) __name__ __module__ __qualname____doc__r)r1rAr7r8r[r'r'r'r(r;s-  7&r)$Z __future__rrrrZ __metaclass__Zansible.constantsZ constantsCZansible.errorsrrrZansible.module_utils.sixrZansible.module_utils._textr Zansible.parsing.splitterr r Zansible.plugins.loaderr r Zansible.templaterZansible.utils.fqcnrZansible.utils.sentinelrr#ZMODULE_REQUIRE_ARGSr:unionrWrRrr'r'r'r(s