a ì)g& ã@sâddlmZmZmZeZddlmZddlm Z ddlm Z ddl m ZddlmZmZmZddlmZddlmZdd lmZdd lmZdd lmZdd lmZdd lm Z e ƒZ!Gdd„deƒZ"ddd„Z#e$dkrÞe#ƒdS)é)Úabsolute_importÚdivisionÚprint_function)ÚCLI)Ú constants)Úcontext)Úoption_helpers)Ú AnsibleErrorÚAnsibleOptionsErrorÚAnsibleParserError)ÚTaskQueueManager)Úto_text)Úparse_kv)Ú from_yaml)ÚPlaybook)ÚPlay)ÚDisplaycsDeZdZdZdZ‡fdd„Z‡fdd„Zdd„Z‡fd d „Z‡Z S) ÚAdHocCLIz¨ is an extra-simple tool/framework/API for doing 'remote things'. this command allows you to define and run a single task 'playbook' against a set of hosts Úansiblecsòtt|ƒjddddt |j¡t |j¡t |j¡t |j¡t  |j¡t  |j¡t  |j¡t  |j¡t  |j¡t |j¡t |j¡t |j¡|jjddddtjd |jjd d d d tjtjd |jjdddddS)z* create an options parser for bin/ansible z%prog [options]z>Define and run a single task 'playbook' against a set of hostsz=Some actions do not make sense in Ad-Hoc (include, meta, etc))ÚusageZdescÚepilogz-az--argsÚ module_argsz„The action's options in space separated k=v format: -a 'opt1=val1 opt2=val2' or a json string: -a '{"opt1": "val1", "opt2": "val2"}')ÚdestÚhelpÚdefaultz-mz --module-nameÚ module_namez*Name of the action to execute (default=%s)ÚargsÚpatternz host pattern)ÚmetavarrN)ÚsuperrÚ init_parserÚopt_helpZadd_runas_optionsÚparserZadd_inventory_optionsZadd_async_optionsZadd_output_optionsZadd_connect_optionsZadd_check_optionsZadd_runtask_optionsZadd_vault_optionsZadd_fork_optionsZadd_module_optionsZadd_basedir_optionsZadd_tasknoplay_optionsÚ add_argumentÚCZDEFAULT_MODULE_ARGSZDEFAULT_MODULE_NAME)Úself©Ú __class__©ú5/usr/lib/python3.9/site-packages/ansible/cli/adhoc.pyr "s2 þ             ý þzAdHocCLI.init_parsercs,tt|ƒ |¡}|jt_|j|ddd|S)z2Post process and validate options for bin/ansible T)Z runas_optsZ fork_opts)rrÚpost_process_argsÚ verbosityÚdisplayZvalidate_conflicts)r%Úoptionsr&r(r)r*?szAdHocCLI.post_process_argscCsÌtjdtjv}tjd}d}|r^| d¡r^| d¡r^zt| ¡dd}Wnty\Yn0|snt ||d}tjd|dœtjd d œ}tjdtj vrºt t ||fƒƒrº||d <||d <t d |d|gdS)Nrrú{ú}T)Z json_only)Ú check_raw)ÚmodulerZ task_timeout)ÚactionÚtimeoutÚ async_valÚpollzAnsible Ad-HocÚno)ÚnameÚhostsZ gather_factsZtasks)rÚCLIARGSr$ÚMODULE_REQUIRE_ARGSÚ startswithÚendswithrÚstripr rZ_ACTION_ALL_INCLUDE_ROLE_TASKSÚanyÚ frozensetÚdict)r%rr4r5r0Zmodule_args_rawrZmytaskr(r(r)Ú_play_dsIs,   ÿ üzAdHocCLI._play_dsc s–tt|ƒ ¡ttjddd}d}d}| ¡\}}||dœ}| ¡\}}}z| |tjd|¡}Wn.t y’tjdr€‚ng}t   d¡Yn0tjdrÌt   d t |ƒ¡|D]} t   d | ¡q´d Stjd t jvrtjd sdtjd } | d¡r | d} t| ƒ‚tjd t jvr8tdtjd ƒ‚| |tjdtjd¡} tƒj| ||d} t|ƒ} | j | ¡d| _|jrŽ|j}n2tjdr d}n t jr¼t jdkr¼t j}nd}d}tjdrìt j d¡tjdt _d}d|_z|t|||||t j|tjdd|_|j  ¡|j !d| ¡|j | ¡}|j !d |jj"¡W|jr`|j #¡|r’| $¡n"|jr‚|j #¡|r| $¡0|S)!z- create and execute the single task playbook rZsurrogate_or_strict)ÚerrorsN)Z conn_passZ become_passZsubsetzNo hosts matched, nothing to doZ listhostsz hosts (%d):z %srrrzNo argument passed to %s modulez.ymlz( (did you mean to run ansible-playbook?)z.'%s' is not a valid action for ad-hoc commandsZsecondsZ poll_interval)Úvariable_managerÚloaderZ__adhoc_playbook__Zone_lineZonelinerZminimalFZtreeTÚforks)Ú inventoryrCrDÚ passwordsZstdout_callbackZrun_additional_callbacksÚrun_treerEZv2_playbook_on_startZv2_playbook_on_stats)%rrÚrunr rr9Z ask_passwordsZ _play_prereqsZ get_host_listr r,ZwarningÚlenr$r:r<r Z_ACTION_IMPORT_PLAYBOOKrArÚloadrZ_entriesÚappendZ _file_nameÚcallbackZDEFAULT_LOAD_CALLBACK_PLUGINSZDEFAULT_STDOUT_CALLBACKZCALLBACKS_ENABLEDZTREE_DIRZ_tqmr Zload_callbacksZ send_callbackZ_statsZcleanupZcleanup_all_tmp_files)r%rZsshpassZ becomepassrGrDrFrCr8ÚhostÚerrZplay_dsZplayZplaybookÚcbrHÚresultr&r(r)rIesŒ      ÿ     ø    ý  z AdHocCLI.run) Ú__name__Ú __module__Ú __qualname__Ú__doc__r7r r*rArIÚ __classcell__r(r(r&r)rs   rNcCst |¡dS)N)rZ cli_executor)rr(r(r)ÚmainÊsrWÚ__main__)N)%Z __future__rrrÚtypeZ __metaclass__Z ansible.clirrrr$rZansible.cli.argumentsrr!Zansible.errorsr r r Z#ansible.executor.task_queue_managerr Zansible.module_utils._textr Zansible.parsing.splitterrZansible.parsing.utils.yamlrZansible.playbookrZansible.playbook.playrZansible.utils.displayrr,rrWrRr(r(r(r)Ús&           0