a )gF@sddlmZmZmZeZddlZddlZddlZddl Z ddl Z ddl Z ddl Z ddl mZddlZddlmZddlmZddlmZmZddlmZddlmZGdd d ejZGd d d ejZGd d d ejZGdddejZ ddZ!dAddZ"ddZ#ddZ$ddZ%dBddZ&dCdd Z'd!d"Z(d#d$Z)d%d&Z*d'd(Z+d)d*Z,d+d,Z-d-d.Z.d/d0Z/d1d2Z0d3d4Z1d5d6Z2dDd7d8Z3d9d:Z4d;d<Z5d=d>Z6d?d@Z7dS)E)absolute_importdivisionprint_functionN) __version__) constants) to_native) HAS_LIBYAML yaml_load unfrackpathcseZdZfddZZS)SortingHelpFormattercs&t|tdd}tt||dS)Noption_strings)key)sortedoperator attrgettersuperr add_arguments)selfactions __class__H/usr/lib/python3.9/site-packages/ansible/cli/arguments/option_helpers.pyrsz"SortingHelpFormatter.add_arguments)__name__ __module__ __qualname__r __classcell__rrrrr sr c@seZdZdddZdS)AnsibleVersionNcCs&ttt|d}t||dS)Nprog)rversiongetattrprintexit)rparser namespacevalues option_stringZansible_versionrrr__call__#szAnsibleVersion.__call__)N)rrrr(rrrrr"srcs(eZdZd fdd Zd ddZZS) UnrecognizedArgumentTNFrc s"tt|j|||||||ddS)N)r destnargsconstdefaultrequiredhelp)rr)__init__) rr r*r,r-r.r/metavarr+rrrr0*szUnrecognizedArgument.__init__cCs|d|dS)Nzunrecognized arguments: %s)error)rr$r%r&r'rrrr(.szUnrecognizedArgument.__call__)TNFNNr)N)rrrr0r(rrrrrr))sr)cs,eZdZdZdfdd Zd ddZZS) PrependListActionznA near clone of ``argparse._AppendAction``, but designed to prepend list values instead of appending. NFc sX|dkrtd|dur0|tjkr0tdtjtt|j||||||||| | d dS)Nrznargs for append actions must be > 0; if arg strings are not supplying the value to append, the append const action may be more appropriatez nargs must be %r to supply const) r r*r+r,r-typechoicesr.r/r1) ValueErrorargparseOPTIONALrr3r0) rr r*r+r,r-r4r5r.r/r1rrrr06s  zPrependListAction.__init__cCs2tt||jg}||dd<t||j|dS)Nr)copy ensure_valuer*setattr)rr$r%r&r'itemsrrrr(Ks zPrependListAction.__call__)NNNNNFNN)N)rrr__doc__r0r(rrrrrr32s r3cCs&t||ddurt|||t||S)N)r!r;)r%namevaluerrrr:Qs r:FTcsfdd}|S)z=Turn an Option's data into a single path in Ansible locationscs6rfdd|tjDS|dkr*|St|dS)Ncsg|]}|rt|dqS)followr ).0xr@rr ^z/unfrack_path..inner..-r@)splitospathsepr r?rArIrrinner\s zunfrack_path..innerr)rIrArLrrKr unfrack_pathZsrMcsfdd}|S)Ncs"|rt|ddS|S)N) startswithr rJbeaconrrrLis z!maybe_unfrack_path..innerr)rQrLrrPrmaybe_unfrack_pathgs rRc Csd}tj|rtj|rzbt|}t|d}Wdn1sL0Ytj|rh|}ntj|dd|}Wnt t fyYdS0ttj|dD}| d}| drtj||dd}nd}Wdn1s0Y|rhtj|rhd |d d d}t| }| dd }Wdn1s\0Yn|dd }d }tj|d}tt|j}tjd krtj} ntj} d||td|t| d}nd}|S)zC returns a string containing git branch, commit id and commit date NgitdirZHEAD zref:/ z detached HEADrz)({0} {1}) last updated {2} (GMT {3:+04d})z%Y/%m/%d %H:%M:%Si)rHpathexistsisfileopenr getisabsjoinIOErrorAttributeErrorreadlinerstriprOrGtime localtimestatst_mtimedaylighttimezonealtzoneformatstrftimeint) repo_pathresultfrSlineZ branch_pathbranchZcommitdateoffsetrrr_git_repo_infops<  ,  " 2  "rwc Cs:tjtjtjtdddd}tj|d}t|S)Nz..z.git)rHr[normpathradirname__file__rw)basedirrprrr_gitinfos$r|cCs|rd|tg}ntg}t}|r8d|d||d<|dtjtjdurXd}ntj}|d||dd tj |d d tj |d t j d|d d t j tt jf|dt|dtd|S)z return ansible version z{0} [core {1}]z{0} {1}rz config file = %sNzDefault w/o overridesz$ configured module search path = %sz% ansible python module location = %s:z" ansible collection location = %sz executable location = %sz python version = %s (%s)rUz jinja version = %sz libyaml = %srV)rmrr|appendCZ CONFIG_FILEDEFAULT_MODULE_PATHraansible__path__ZCOLLECTIONS_PATHSsysargvr splitlinesr executable j2_versionr)rrqZgitinfoZcpathrrrr s$ $r rUcCs6tj|t||dd}d}|jdtd|dt||S)z: Create an options parser for all ansible scripts resolve)rformatter_classepilog descriptionconflict_handlerzshow program's version number, config file location, configured module search path, module location, executable location and exitz --versionr)actionr+r/)r7ArgumentParserr add_argumentradd_verbosity_options)rusageZdescrr$Z version_helprrrcreate_base_parsersrcCs|jdddtjddddS)zAdd options for verbosityz-vz --verbose verbositycountzCauses Ansible to print more debug messages. Adding multiple -v will increase the verbosity, the builtin plugins currently evaluate up to -vvvvvv. A reasonable level to start is -vvv, connection debugging might require -vvvv.r*r-rr/N)rrZDEFAULT_VERBOSITYr$rrrrsrcCs8|jddtjtddtjd|jdddtd d d d S) z5Add options for commands which can launch async tasksz-Pz--pollZ poll_intervalz.set the poll interval if using -B (default=%s)r-r4r*r/z-Bz --backgroundZsecondsrz9run asynchronously, failing after X seconds (default=N/A))r*r4r-r/N)rrZDEFAULT_POLL_INTERVALrorrrradd_async_optionss rcCs|jdtjdddtddS)z9Add options for commands which can set a playbook basedirz--playbook-dirr{storezSince this tool does not use playbooks, use this as a substitute playbook directory. This sets the relative path for many features including roles/ group_vars/ etc.)r-r*rr/r4N)rrZ PLAYBOOK_DIRrMrrrradd_basedir_optionssrcCs2|jddddddd|jdd tjd dd dd S) zKAdd options for commands which can run with diagnostic information of tasksz-Cz--checkFcheck store_truezRdon't make any changes; instead, try to predict some of the changes that may occurr-r*rr/z-Dz--diffdiffzhwhen changing (small) files and templates, show the differences in those files; works great with --checkN)rrZ DIFF_ALWAYSrrrradd_check_optionss rc Cs|dd}|jddtjddtd|jdd tjd d tjd |jd ddtjdtjd|jddtjtddtjd|jddddd |jddddd |jdddd d |jd!dd"d#d ||| }|jd$d%tj d&d'd(d)|jd*d+tj d,d-td.d/||dS)0z@Add options for commands which need to connection to other hostszConnection Optionsz+control as whom and how to connect to hostsz --private-keyz --key-fileZprivate_key_filez,use this file to authenticate the connection)r-r*r/r4z-uz--userZ remote_userz!connect as this user (default=%s)r-r*r/z-cz --connectionZ connectionz#connection type to use (default=%s)r*r-r/z-Tz --timeouttimeoutz7override the connection timeout in seconds (default=%s)rz--ssh-common-argsNZssh_common_argszDspecify common arguments to pass to sftp/scp/ssh (e.g. ProxyCommand)z--sftp-extra-argsZsftp_extra_argsz:specify extra arguments to pass to sftp only (e.g. -f, -l)z--scp-extra-argsZscp_extra_argsz5specify extra arguments to pass to scp only (e.g. -l)z--ssh-extra-argsZssh_extra_argsz5specify extra arguments to pass to ssh only (e.g. -R)z-kz --ask-passZask_passrzask for connection passwordrz--connection-password-filez--conn-pass-fileZconnection_password_filezConnection password filerr-r*r/r4r) add_argument_grouprrZDEFAULT_PRIVATE_KEY_FILErMZDEFAULT_REMOTE_USERZDEFAULT_TRANSPORTZDEFAULT_TIMEOUTroadd_mutually_exclusive_groupZDEFAULT_ASK_PASSZCONNECTION_PASSWORD_FILE)r$Z connect_groupZconnect_password_grouprrradd_connect_optionssD      rcCs"|jdddtjtdtjddS)z7Add options for commands that can fork worker processesz-fz--forksZforksz8specify number of parallel processes to use (default=%s))r*r-r4r/N)rrZ DEFAULT_FORKSrorrrradd_fork_optionssrcCsB|jddddddd|jdd d d d|jd d tjddddS)z/Add options for commands that utilize inventoryz-iz --inventoryz--inventory-fileZ inventoryr~zXspecify inventory host path or comma separated host list. --inventory-file is deprecatedr*rr/z --list-hostsZ listhostsrz@outputs a list of matching hosts; does not execute anything elsez-lz--limitZsubsetz5further limit selected hosts to an additional patternrN)rrZDEFAULT_SUBSETrrrradd_inventory_optionss rcCs,|jdtjdddd|jddddd d S) zJAdd options for commands which can launch meta tasks from the command linez--force-handlersZforce_handlersrz!run handlers even if a task failsrz --flush-cacheZ flush_cachez0clear the fact cache for every host in inventoryrN)rrZDEFAULT_FORCE_HANDLERSrrrradd_meta_options%s  rc Cs:tjddd}|jddddd|td d td dS) z*Add options for commands that load modulesrr-rUz-Mz --module-path module_pathNz>prepend colon-separated path(s) to module library (default=%s)T)rI)r*r-r/r4r)rZconfigZget_configuration_definitionr_rrMr3)r$rrrradd_module_options-s   rcCs,|jdddddd|jddd d d d d S) z6Add options for commands which can change their outputz-oz --one-lineZone_linerzcondense outputr-tz--treeZtreeNzlog output to this directoryr)rrrrradd_output_options5s   rcCsr|dd}|jddtjdddd|jd d tjd tjd d |jdddtdtjd||t|dS)z Add options for commands which can run tasks as another user Note that this includes the options from add_runas_prompt_options(). Only one of these functions should be used. zPrivilege Escalation Optionsz8control how and which user you become as on target hostsz-bz--becomerZbecomez>run operations with become (does not imply password prompting))r-rr*r/z--become-methodZ become_methodz/privilege escalation method to use (default=%s)z7, use `ansible-doc -t become -l` to list valid choices.rz --become-userNZ become_userz(run operations as this user (default=%s))r-r*r4r/)rrrZDEFAULT_BECOMEZDEFAULT_BECOME_METHODstrZDEFAULT_BECOME_USERadd_runas_prompt_options)r$ runas_grouprrradd_runas_options=s    rc Cs\|dur|||}|jddddtjdd|jdd tjd d td d ||dS)z Add options for commands which need to prompt for privilege escalation credentials Note that add_runas_options() includes these options already. Only one of the two functions should be used. Nz-Kz--ask-become-passZbecome_ask_passrz%ask for privilege escalation password)r*rr-r/z--become-password-filez--become-pass-fileZbecome_password_filezBecome password filerr)rrrrZDEFAULT_BECOME_ASK_PASSZBECOME_PASSWORD_FILErM)r$rZrunas_pass_grouprrrrTs  rc Cs |jddddtddgddS) z(Add options for commands that run a taskz-ez --extra-varsZ extra_varsr~@zNset additional variables as key=value or YAML/JSON, if filename prepend with @)r*rr4r/r-N)rrRrrrradd_runtask_optionsisrcCs|jdtddtjdddS)z;Add options for commands that run a task w/o a defined playz--task-timeoutZ task_timeoutrzsT        +   "