관리-도구
편집 파일: console.cpython-39.pyc
a �����)g�U����������������������@���s0��d�dl�mZmZmZ�eZd�dlmZ�d�dlZd�dl Z d�dl Z d�dlZd�dlZd�dl Z d�dlmZ�d�dlmZ�d�dlmZ�d�dlmZ�d�dlmZmZ�d�d lmZ�d�d lmZ�d�dlmZ�d�dl m!Z!�d�d l"m#Z#m$Z$�d�dl%m&Z&�d�dl'm(Z(�d�dl)m*Z*�e*��Z+G�dd��dee j,�Z-ddd�Z.e/dk�r,e.���dS�)�����)�absolute_import�division�print_function)�CLIN)� constants)�context)�option_helpers)�TaskQueueManager)� to_native�to_text)�boolean)�parse_kv)�Play)�list_plugins)� module_loader�fragment_loader)�plugin_docs)�stringc)�Displayc�����������������������s���e�Zd�ZdZdZg�ZddiZejp&ej Z ��fdd�Z��fdd�Z��fd d �Z dd��Zd d��Zdd��Zdd��Zdfdd�Zdd��Zdd��Zdd��Zdd��Zdd��Zd d!��ZeZeZd"d#��Zd$d%��Zd&d'��Zd(d)��Zd*d+��Zd,d-��Z d.d/��Z!d0d1��Z"d2d3��Z#d4d5��Z$d6d7��Z%d8d9��Z&d:d;��Z'd<d=��Z(d>d?��Z)d@dA��Z*dBdC��Z+dDdE��Z,dFdG��Z-dHdI��Z.dJdK��Z/dLdM��Z0dNdO��Z1dPdQ��Z2dRdS��Z3dTdU��Z4dVdW��Z5e4Z6e5Z7dXdY��Z8dZd[��Z9d\d]��Z:d^d_��Z;d`da��Z<��fdbdc�Z=ddde��Z>���Z?S�)g� ConsoleCLIa��� A REPL that allows for running ad-hoc tasks against a chosen inventory from a nice shell with built-in tab completion (based on dominis' ansible-shell). It supports several commands, and you can modify its configuration at runtime: - `cd [pattern]`: change host/group (you can use host patterns eg.: app*.dc*:!app01*) - `list`: list available hosts in the current path - `list groups`: list groups included in the current path - `become`: toggle the become flag - `!`: forces shell module instead of the ansible module (!yum update -y) - `verbosity [num]`: set the verbosity level - `forks [num]`: set the number of forks - `become_user [user]`: set the become_user - `remote_user [user]`: set the remote_user - `become_method [method]`: set the privilege escalation method - `check [bool]`: toggle check mode - `diff [bool]`: toggle diff mode - `timeout [integer]`: set the timeout of tasks in seconds (0 to disable) - `help [command/module]`: display documentation for the command or module - `exit`: exit ansible-console zansible-consolezhost-patternz�A name of a group in the inventory, a shell-like glob selecting hosts in inventory or any combination of the two separated by commas.c��������������������s����t�t|���|��d|�_g�|�_g�|�_d�|�_d�|�_d�|�_t ��|�_ d|�_d�|�_d�|�_ d�|�_d�|�_d�|�_d�|�_d�|�_d�|�_d�|�_tj�|���d�S�)NzAWelcome to the ansible console. Type help or ? to list commands. �*)�superr����__init__Zintro�groups�hosts�pattern�variable_manager�loader�dict� passwords�cwd�remote_user�become�become_user� become_method� check_mode�diff�forks�task_timeout�collections�cmd�Cmd��self�args�� __class__���7/usr/lib/python3.9/site-packages/ansible/cli/console.pyr���H���s&����zConsoleCLI.__init__c��������������������s����t�t|��jddd��t�|�j��t�|�j��t�|�j��t�|�j��t� |�j��t� |�j��t�|�j��t�|�j��t� |�j��t�|�j��|�jjdddddd��|�jjd d ddd ��d�S�)Nz)REPL console for executing Ansible tasks.zgThis is not a live session/connection: each task is executed in the background and returns its results.)Zdesc�epilogr���zhost pattern�all�?)�help�metavar�default�nargsz--step�step� store_truez4one-step-at-a-time: confirm each task before running)�dest�actionr6���)r���r����init_parser�opt_helpZadd_runas_options�parserZadd_inventory_optionsZadd_connect_optionsZadd_check_optionsZadd_vault_optionsZadd_fork_optionsZadd_module_optionsZadd_basedir_optionsZadd_runtask_optionsZadd_tasknoplay_options�add_argument�r-���r/���r1���r2���r>���d���s$���� ��zConsoleCLI.init_parserc��������������������s,���t�t|���|�}|jt_|�j|ddd��|S�)NT)Z runas_optsZ fork_opts)r���r����post_process_args� verbosity�displayZvalidate_conflicts)r-����optionsr/���r1���r2���rC���y���s����zConsoleCLI.post_process_argsc�����������������C���s���t�|��S��N)�dirrB���r1���r1���r2���� get_names���s����zConsoleCLI.get_namesc�����������������C���sT���zt�j�|���W�n>�ty*���|�����Y�n&�tyN���|��d��|��|���Y�n0�d�S�)Nz[Ansible-console was exited])r*���r+����cmdloop�KeyboardInterrupt�EOFErrorrE����do_exitrB���r1���r1���r2���rJ�������s���� zConsoleCLI.cmdloopc�����������������C���sz���|�j�pt���}|�j�|�j�|�_d||�jt|�j�|�jf�}|�j rX|�j dv�rX|d7�}tj}n|d7�}|�j }t||dd�|�_d�S�)Nz%s@%s (%d)[f:%s])N�rootz# z$ T)Zwrap_nonvisible_chars)r!����getpassZgetuser� inventory� list_hostsr ����selected�lenr'���r"���r#����CZCOLOR_ERROR� NORMAL_PROMPTr����prompt)r-���Z login_userrV���Zcolorr1���r1���r2���� set_prompt����s����zConsoleCLI.set_promptc�����������������C���s���t�d|�j�S�)N�module)r���r)���rB���r1���r1���r2����list_modules����s����zConsoleCLI.list_modulesFc�������������� ���C���sh��|��d�rdS�|�js"t�d��dS�d}|}|dur`|���^}}t�|�r`|}|r\d�|�}nd}|�jrn|�j}nt j r�t jdkr�t j}nd }d }zr|t jv�} t t |t|| d�d�|�jd �} t d|�jd| g|�j|�j|�j|�j|�j|�j|�jd�}t��j||�j|�jd�}W�n:�t�y:�} �z t�dt| ����W�Y�d } ~ dS�d } ~ 0�0�z�d |�_zdt|�j|�j|�j|�j |t j d|�j!d�|�_|�j�"|�}t�#|��W�|�j�r�|�j�$���|�j�r�|�j�%���n&|�j�r�|�j�$���|�j�r�|�j�%���0�|d u��r�t�d��W�dS�W�nv�t&�y���t�d��Y�dS��t�yb�} �z>|�j'dk�r>dd l(}t�)|�*����t�t| ���W�Y�d } ~ dS�d } ~ 0�0�d S�)z actually runs modules �#Fz No host found�shellT� ��r8���ZminimalN)� check_raw)rX���r.���)r=����timeoutz Ansible Shell�no)�namer���Zgather_factsZtasksr!���r"���r#���r$���r%���r&���r)���)r���r���zUnable to build command: %s)rP���r���r���r���Zstdout_callbackZrun_additional_callbacksZrun_treer'���zNo hosts foundzUser interrupted execution����r���)+� startswithr ���rE����error�splitr����find_plugin�join�callbackrT���ZDEFAULT_LOAD_CALLBACK_PLUGINSZDEFAULT_STDOUT_CALLBACKZ_ACTION_ALLOWS_RAW_ARGSr���r ���r(���r!���r"���r#���r$���r%���r&���r)���r����loadr���r���� Exceptionr���Z_tqmr ���rP���r���r'����run�debugZcleanupZcleanup_all_tmp_filesrK���rD���� traceback�v� format_exc)r-����lineZ forceshellrX����module_argsZpossible_moduleZ possible_args�cb�resultr^���ZtaskZplay_dsZplay�erm���r1���r1���r2���r8�������s����� � � � zConsoleCLI.defaultc�����������������C���s���d�S�rG���r1���rB���r1���r1���r2���� emptyline����s����zConsoleCLI.emptylinec�����������������C���s���|���|d��dS�)a�� You can run shell commands through the shell module. eg.: shell ps uax | grep java | wc -l shell killall python shell halt -n You can use the ! to force the shell module. eg.: !ps aux | grep java | wc -l TN�r8����r-����argr1���r1���r2����do_shell����s����zConsoleCLI.do_shellc�����������������C���s���t���d��d�S�)Nz4You can run shell commands through the shell module.�rE���rB���r1���r1���r2���� help_shell��s����zConsoleCLI.help_shellc�����������������C���sf���|rZzt�|�}W�n$�ty4���t�d��|�����Y�n0�|dkrN||�_|�����qbt�d��n|�����dS�)zSet the number of forkszInvalid argument for "forks"r���z(forks must be greater than or equal to 1N)�int� TypeErrorrE���rd����usage_forksr'���rW���)r-���rx���r'���r1���r1���r2����do_forks��s���� zConsoleCLI.do_forksc�����������������C���s���t���d��|�����d�S�)Nz'Set the number of forks to use per task)rE���r~���rB���r1���r1���r2���� help_forks��s���� zConsoleCLI.help_forksc�����������������C���s���t���d��d�S�)NzUsage: forks <number>rz���rB���r1���r1���r2���r~�����s����zConsoleCLI.usage_forksc�����������������C���s~���|dv�rd|�_�nB|s|�����n4|�d�}|D�]$}|�j�du�r@g�|�_�|�j��|�����q,|�j�rpt�dd�|�j�����n t�d��dS�)z.Set list of collections for 'short name' usage)r]���ZnoneN�,z%Collections name search is set to: %sz, z)Collections name search is using defaults)r)����usage_collectionsre����append�striprE���rn���rg���)r-���rx���r)���Z collectionr1���r1���r2����do_collections$��s���� zConsoleCLI.do_collectionsc�����������������C���s���t���d��|�����d�S�)NzFSet the collection name search path when using short names for plugins)rE���r����rB���r1���r1���r2����help_collections6��s���� zConsoleCLI.help_collectionsc�����������������C���s���t���d��d�S�)NzgUsage: collections <collection1>[, <collection2> ...] Use empty quotes or "none" to reset to default. rz���rB���r1���r1���r2���r����:��s����zConsoleCLI.usage_collectionsc�������������� ���C���sl���|st���d��nXzt|�t�_t��d|���W�n:�ttfyf�}�zt��dt|����W�Y�d}~n d}~0�0�dS�)zSet verbosity levelzUsage: verbosity <number>zverbosity level set to %sz)The verbosity must be a valid integer: %sN)rE���r|���rD���rn���r}���� ValueErrorrd���r���)r-���rx���rt���r1���r1���r2����do_verbosity=��s���� zConsoleCLI.do_verbosityc�����������������C���s���t���d��d�S�)Nz@Set the verbosity level, equivalent to -v for 1 and -vvvv for 4.rz���rB���r1���r1���r2����help_verbosityH��s����zConsoleCLI.help_verbosityc�����������������C���sF���|sd|�_�n.|dv�rd|�_�n|�j�|�r0||�_�n t�d��|�����dS�)a�� Change active host/group. You can use hosts patterns as well eg.: cd webservers cd webservers:dbservers cd webservers:!phoenix cd webservers:&staging cd webservers:dbservers:&staging:!phoenix r���z/*r4���zno host matchedN)r ���rP���Z get_hostsrE���rW���rw���r1���r1���r2����do_cdK��s���� zConsoleCLI.do_cdc�����������������C���s���t���d��|�����d�S�)NzChange active host/group. )rE����usage_cdrB���r1���r1���r2����help_cd_��s���� zConsoleCLI.help_cdc�����������������C���s���t���d��d�S�)Nz'Usage: cd <group>|<host>|<host pattern>rz���rB���r1���r1���r2���r����c��s����zConsoleCLI.usage_cdc�����������������C���sT���|s|�j�D�]}t�|j��q n2|dkr>|�jD�]}t�|��q,nt�d��|�����dS�)z#List the hosts in the current groupr���zInvalid option passed to "list"N)rR���rE���ra���r���rd���� help_list)r-���rx����host�groupr1���r1���r2����do_listf��s���� zConsoleCLI.do_listc�����������������C���s���t���d��d�S�)NzLList the hosts in the current group or a list of groups if you add 'groups'.rz���rB���r1���r1���r2���r����r��s����zConsoleCLI.help_listc�����������������C���s:���|r,t�|dd�|�_t�d|�j���|�����n t�d��dS�)z$Toggle whether plays run with becomeF��strictzbecome changed to %sz.Please specify become value, e.g. `become yes`N)r���r"���rE���rn���rW���rw���r1���r1���r2���� do_becomeu��s ���� zConsoleCLI.do_becomec�����������������C���s���t���d��d�S�)Nz,Toggle whether the tasks are run with becomerz���rB���r1���r1���r2����help_become~��s����zConsoleCLI.help_becomec�����������������C���s"���|r||�_�|�����n t�d��dS�)z6Given a username, set the remote user plays are run byz5Please specify a remote user, e.g. `remote_user root`N)r!���rW���rE���rw���r1���r1���r2����do_remote_user���s���� zConsoleCLI.do_remote_userc�����������������C���s���t���d��d�S�)Nz2Set the user for use as login to the remote targetrz���rB���r1���r1���r2����help_remote_user���s����zConsoleCLI.help_remote_userc�����������������C���s2���|r||�_�nt�d��t�d|�j����|�����dS�)zFGiven a username, set the user that plays are run by when using becomez1Please specify a user, e.g. `become_user jenkins`zCurrent user is %sN)r#���rE���rn���rW���rw���r1���r1���r2����do_become_user���s ���� zConsoleCLI.do_become_userc�����������������C���s���t���d��d�S�)NznSet the user for use with privilege escalation (which remote user attempts to 'become' when become is enabled)rz���rB���r1���r1���r2����help_become_user���s����zConsoleCLI.help_become_userc�����������������C���s:���|r||�_�t�d|�j����nt�d��t�d|�j����dS�)zLGiven a become_method, set the privilege escalation method when using becomezbecome_method changed to %sz7Please specify a become_method, e.g. `become_method su`zCurrent become_method is %sN)r$���rE���rn���rw���r1���r1���r2����do_become_method���s ���� zConsoleCLI.do_become_methodc�����������������C���s���t���d��d�S�)NzASet the privilege escalation plugin to use when become is enabledrz���rB���r1���r1���r2����help_become_method���s����zConsoleCLI.help_become_methodc�����������������C���sB���|r$t�|dd�|�_t�d|�j���nt�d��t�d|�j���dS�)z(Toggle whether plays run with check modeFr����zcheck mode changed to %sz1Please specify check mode value, e.g. `check yes`zcheck mode is currently %s.N)r���r%���rE���rn���rw���r1���r1���r2����do_check���s ���� zConsoleCLI.do_checkc�����������������C���s���t���d��d�S�)NzToggle check_mode for the tasksrz���rB���r1���r1���r2���� help_check���s����zConsoleCLI.help_checkc�����������������C���sB���|r$t�|dd�|�_t�d|�j���nt�d��t�d|�j���dS�)z"Toggle whether plays run with diffFr����zdiff mode changed to %sz-Please specify a diff value , e.g. `diff yes`zdiff mode is currently %sN)r���r&���rE���rn���rw���r1���r1���r2����do_diff���s ���� zConsoleCLI.do_diffc�����������������C���s���t���d��d�S�)Nz Toggle diff output for the tasksrz���rB���r1���r1���r2���� help_diff���s����zConsoleCLI.help_diffc�������������� ���C���st���|rhz&t�|�}|dk�r"t�d��n||�_W�qp�ttfyd�}�zt�dt|����W�Y�d}~qpd}~0�0�n|�����dS�)zSet the timeoutr���z@The timeout must be greater than or equal to 1, use 0 to disablezAThe timeout must be a valid positive integer, or 0 to disable: %sN)r|���rE���rd���r(���r}���r����r���� usage_timeout)r-���rx���r_���rt���r1���r1���r2���� do_timeout���s���� *zConsoleCLI.do_timeoutc�����������������C���s���t���d��|�����d�S�)NzSet task timeout in seconds)rE���r����rB���r1���r1���r2����help_timeout���s���� zConsoleCLI.help_timeoutc�����������������C���s���t���d��d�S�)NzUsage: timeout <seconds>rz���rB���r1���r1���r2���r�������s����zConsoleCLI.usage_timeoutc�����������������C���s���t�j�d��dS�)zExits from the consolez Ansible-console was exited. ���)�sys�stdout�writer,���r1���r1���r2���rM������s����zConsoleCLI.do_exitc�����������������C���s���t���d��d�S�)NzLEAVE!rz���rB���r1���r1���r2���� help_exit���s����zConsoleCLI.help_exitc�����������������C���s����|r�t��|�}|r�t�|t�\}}}}|r�t�|d���t�d��|d����D�]2}t�dt||�j��d�|d�|�d�d����qNq�t� d|���nt� d |���d�S�) NZshort_descriptionzParameters:rF���z r\����descriptionr���zNo documentation found for %s.z<%s is not a valid command, use ? to list all valid commands.) r���rf���r���� get_docstringr���rE����keysr���rU���rd���)r-����module_name�in_path�oc�a�_dummy1�_dummy2�optr1���r1���r2����helpdefault���s���� 2zConsoleCLI.helpdefaultc�����������������C���s���t��d��d�S�)NzDon't be redundant!)rE���ZwarningrB���r1���r1���r2���� help_help���s����zConsoleCLI.help_helpc��������������������sb���|��d�d���t���t|���|�jdv�r6|�j|�j�}ndd��|�j�|�j�D��}���fdd�|D��S�)Nr\�������)r4���r����\c�����������������S���s���g�|�] }|j��qS�r1����ra�����.0�xr1���r1���r2���� <listcomp>��������z*ConsoleCLI.complete_cd.<locals>.<listcomp>c��������������������s.���g�|�]&}t�|��t�����rt�|��d����qS�rG���)r ���rc����r�����s�ZmlineZoffsr1���r2���r�������r����)� partitionrS���r ���r���r���rP���rQ����r-����textrp���ZbegidxZendidxZcompletionsr1���r����r2����complete_cd���s���� zConsoleCLI.complete_cdc��������������������s\���|����d�|����v�rX|��d�d���t���t|���|��|����d��}���fdd�|D��S�d�S�)Nr���r\���r����c��������������������s&���g�|�]}|�����r|�d���d��qS�)N�=)rc���r����r����r1���r2���r�������r����z.ConsoleCLI.completedefault.<locals>.<listcomp>)re���rY���rS���rq���r����r1���r����r2����completedefault���s ����zConsoleCLI.completedefaultc�����������������C���s2���t��|�}tj|tdd�\}}}}t|d�����S�)NT)Z is_modulerF���)r���rf���r���r����r����listr����)r-���r����r����r����r����r����r����r1���r1���r2���rq�����s���� zConsoleCLI.module_argsc��������������������s���t�t�������d�}d�}tjd���_��j��_tjd���_tjd���_tjd���_ tjd���_ tjd���_tjd���_tjd���_ tjd ���_tjd �r�tjd �D�]}|r�t�|��q��������_��jD�]<}t��d|�|f��fdd � ��t��d|�|f��fdd � ��q����\}}||d���_�����\��_��_��_�����jtjd���j�}��j�����_dd��|D����_dtjv��rxt� d��n t� d��t!j"�#t!j"�$d�d�}zt�%|��W�n�t&�y����Y�n0�t'�(tj)|�����*������+���d�S�)Nr���r!���r"���r#���r$����checkr&���r'���r(���Zmodule_path�do_c��������������������s�������|d�|���S��Nr\���rv����rx���rX���rB���r1���r2����<lambda>$��r����z ConsoleCLI.run.<locals>.<lambda>�help_c��������������������s �������|��S�rG����r�����rX���rB���r1���r2���r����%��r����)Z conn_passZbecome_passZsubsetc�����������������S���s���g�|�] }|j��qS�r1���r����r����r1���r1���r2���r����/��r����z"ConsoleCLI.run.<locals>.<listcomp>�libeditzbind ^I rl_completez tab: complete�~z.ansible-console_history),r���r���rk���r���ZCLIARGSr���r ���r!���r"���r#���r$���r%���r&���r'���r(���r���Z add_directoryrY����modules�setattrZ ask_passwordsr���Z _play_prereqsr���rP���r���Z get_host_listZlist_groupsr���r����readline�__doc__�parse_and_bind�os�pathrg���� expanduser�read_history_file�IOError�atexit�register�write_history_filerW���rJ���)r-���ZsshpassZ becomepassr����rX���r���Zhistfiler/���rB���r2���rk�����sL���� zConsoleCLI.runc��������������������s����d}|��d�rJ|�dd�}t�|�r�t��||f��fdd� ��t���|�}nD|��d�r�|�dd�}t�|�r�t��||f��fdd� ��t���|�}|du�r�t��j��d|��d ���|S�) z[ handle not found to populate dynamically a module function if module matching name exists Nr����r]���c��������������������s�������|d�|���S�r����rv���r����rB���r1���r2���r����I��r����z(ConsoleCLI.__getattr__.<locals>.<lambda>r����c��������������������s �������|��S�rG���r����r����rB���r1���r2���r����N��r����z does not have a z attribute) rc����replacer���rf���r�����object�__getattr__�AttributeErrorr0���)r-���ra����attrrX���r1���rB���r2���r����B��s���� zConsoleCLI.__getattr__)F)@�__name__� __module__�__qualname__r����ra���r����Z ARGUMENTSrT���ZCOLOR_CONSOLE_PROMPTZCOLOR_HIGHLIGHTrU���r���r>���rC���rI���rJ���rW���rY���r8���ru���ry���r{���r���r����r~���Z do_serialZhelp_serialr����r����r����r����r����r����r����r����r����r����r����r����r����r����r����r����r����r����r����r����r����r����r����r����r����rM���r����Zdo_EOFZhelp_EOFr����r����r����r����rq���rk���r����� __classcell__r1���r1���r/���r2���r���&���sr��� X <r���c�����������������C���s���t��|���d�S�rG���)r���Zcli_executor)r.���r1���r1���r2����mainW��s����r�����__main__)N)0Z __future__r���r���r����typeZ __metaclass__Zansible.clir���r����r*���rO���r����r����r����Zansibler���rT���r���Zansible.cli.argumentsr���r?���Z#ansible.executor.task_queue_managerr ���Zansible.module_utils._textr ���r���Z)ansible.module_utils.parsing.convert_boolr���Zansible.parsing.splitterr ���Zansible.playbook.playr���Zansible.plugins.listr���Zansible.plugins.loaderr���r���Z ansible.utilsr���Zansible.utils.colorr���Zansible.utils.displayr���rE���r+���r���r����r����r1���r1���r1���r2����<module>���s<�������5