o nnhn@s^ddlmZdZddlmZddlZddlZddlZddl Z ddl Z ddl Z ddl Z ddl Z ddlZddlZddlZddlZddlmZddlmZmZmZmZddlmZmZmZddlmZm Z m!Z!ddl"m#Z#m$Z$dd l%m&Z&dd l'm(Z(dd l)m*Z*m+Z+e(Z,e-d Z.d Z/da0e 1dZ2GdddeZ3e,fd'dd Z4d(d#d$Z5Gd%d&d&e#Z6dS))) annotationsa4 name: ssh short_description: connect via SSH client binary description: - This connection plugin allows Ansible to communicate to the target machines through normal SSH command line. - Ansible does not expose a channel to allow communication between the user and the SSH process to accept a password manually to decrypt an SSH key when using this connection plugin (which is the default). The use of C(ssh-agent) is highly recommended. author: ansible (@core) extends_documentation_fragment: - connection_pipelining version_added: historical notes: - This plugin is mostly a wrapper to the ``ssh`` CLI utility and the exact behavior of the options depends on this tool. This means that the documentation provided here is subject to be overridden by the CLI tool itself. - Many options default to V(None) here but that only means we do not override the SSH tool's defaults and/or configuration. For example, if you specify the port in this plugin it will override any C(Port) entry in your C(.ssh/config). - The ssh CLI tool uses return code 255 as a 'connection error', this can conflict with commands/tools that also return 255 as an error code and will look like an 'unreachable' condition or 'connection error' to this plugin. options: host: description: Hostname/IP to connect to. default: inventory_hostname type: string vars: - name: inventory_hostname - name: ansible_host - name: ansible_ssh_host - name: delegated_vars['ansible_host'] - name: delegated_vars['ansible_ssh_host'] host_key_checking: description: Determines if SSH should reject or not a connection after checking host keys. default: True type: boolean ini: - section: defaults key: 'host_key_checking' - section: ssh_connection key: 'host_key_checking' version_added: '2.5' env: - name: ANSIBLE_HOST_KEY_CHECKING - name: ANSIBLE_SSH_HOST_KEY_CHECKING version_added: '2.5' vars: - name: ansible_host_key_checking version_added: '2.5' - name: ansible_ssh_host_key_checking version_added: '2.5' password: description: Authentication password for the O(remote_user). Can be supplied as CLI option. type: string vars: - name: ansible_password - name: ansible_ssh_pass - name: ansible_ssh_password sshpass_prompt: description: - Password prompt that sshpass should search for. Supported by sshpass 1.06 and up. - Defaults to C(Enter PIN for) when pkcs11_provider is set. default: '' type: string ini: - section: 'ssh_connection' key: 'sshpass_prompt' env: - name: ANSIBLE_SSHPASS_PROMPT vars: - name: ansible_sshpass_prompt version_added: '2.10' ssh_args: description: Arguments to pass to all SSH CLI tools. default: '-C -o ControlMaster=auto -o ControlPersist=60s' type: string ini: - section: 'ssh_connection' key: 'ssh_args' env: - name: ANSIBLE_SSH_ARGS vars: - name: ansible_ssh_args version_added: '2.7' ssh_common_args: description: Common extra args for all SSH CLI tools. type: string ini: - section: 'ssh_connection' key: 'ssh_common_args' version_added: '2.7' env: - name: ANSIBLE_SSH_COMMON_ARGS version_added: '2.7' vars: - name: ansible_ssh_common_args cli: - name: ssh_common_args default: '' ssh_executable: default: ssh description: - This defines the location of the SSH binary. It defaults to V(ssh) which will use the first SSH binary available in $PATH. - This option is usually not required, it might be useful when access to system SSH is restricted, or when using SSH wrappers to connect to remote hosts. type: string env: [{name: ANSIBLE_SSH_EXECUTABLE}] ini: - {key: ssh_executable, section: ssh_connection} #const: ANSIBLE_SSH_EXECUTABLE version_added: "2.2" vars: - name: ansible_ssh_executable version_added: '2.7' sftp_executable: default: sftp description: - This defines the location of the sftp binary. It defaults to V(sftp) which will use the first binary available in $PATH. type: string env: [{name: ANSIBLE_SFTP_EXECUTABLE}] ini: - {key: sftp_executable, section: ssh_connection} version_added: "2.6" vars: - name: ansible_sftp_executable version_added: '2.7' scp_executable: default: scp description: - This defines the location of the scp binary. It defaults to V(scp) which will use the first binary available in $PATH. type: string env: [{name: ANSIBLE_SCP_EXECUTABLE}] ini: - {key: scp_executable, section: ssh_connection} version_added: "2.6" vars: - name: ansible_scp_executable version_added: '2.7' scp_extra_args: description: Extra exclusive to the C(scp) CLI type: string vars: - name: ansible_scp_extra_args env: - name: ANSIBLE_SCP_EXTRA_ARGS version_added: '2.7' ini: - key: scp_extra_args section: ssh_connection version_added: '2.7' cli: - name: scp_extra_args default: '' sftp_extra_args: description: Extra exclusive to the C(sftp) CLI type: string vars: - name: ansible_sftp_extra_args env: - name: ANSIBLE_SFTP_EXTRA_ARGS version_added: '2.7' ini: - key: sftp_extra_args section: ssh_connection version_added: '2.7' cli: - name: sftp_extra_args default: '' ssh_extra_args: description: Extra exclusive to the SSH CLI. type: string vars: - name: ansible_ssh_extra_args env: - name: ANSIBLE_SSH_EXTRA_ARGS version_added: '2.7' ini: - key: ssh_extra_args section: ssh_connection version_added: '2.7' cli: - name: ssh_extra_args default: '' reconnection_retries: description: - Number of attempts to connect. - Ansible retries connections only if it gets an SSH error with a return code of 255. - Any errors with return codes other than 255 indicate an issue with program execution. default: 0 type: integer env: - name: ANSIBLE_SSH_RETRIES ini: - section: connection key: retries - section: ssh_connection key: retries vars: - name: ansible_ssh_retries version_added: '2.7' port: description: Remote port to connect to. type: int ini: - section: defaults key: remote_port env: - name: ANSIBLE_REMOTE_PORT vars: - name: ansible_port - name: ansible_ssh_port keyword: - name: port remote_user: description: - User name with which to login to the remote server, normally set by the remote_user keyword. - If no user is supplied, Ansible will let the SSH client binary choose the user as it normally. type: string ini: - section: defaults key: remote_user env: - name: ANSIBLE_REMOTE_USER vars: - name: ansible_user - name: ansible_ssh_user cli: - name: user keyword: - name: remote_user pipelining: env: - name: ANSIBLE_PIPELINING - name: ANSIBLE_SSH_PIPELINING ini: - section: defaults key: pipelining - section: connection key: pipelining - section: ssh_connection key: pipelining vars: - name: ansible_pipelining - name: ansible_ssh_pipelining private_key_file: description: - Path to private key file to use for authentication. type: string ini: - section: defaults key: private_key_file env: - name: ANSIBLE_PRIVATE_KEY_FILE vars: - name: ansible_private_key_file - name: ansible_ssh_private_key_file cli: - name: private_key_file option: '--private-key' control_path: description: - This is the location to save SSH's ControlPath sockets, it uses SSH's variable substitution. - Since 2.3, if null (default), ansible will generate a unique hash. Use ``%(directory)s`` to indicate where to use the control dir path setting. - Before 2.3 it defaulted to ``control_path=%(directory)s/ansible-ssh-%%h-%%p-%%r``. - Be aware that this setting is ignored if C(-o ControlPath) is set in ssh args. type: string env: - name: ANSIBLE_SSH_CONTROL_PATH ini: - key: control_path section: ssh_connection vars: - name: ansible_control_path version_added: '2.7' control_path_dir: default: ~/.ansible/cp description: - This sets the directory to use for ssh control path if the control path setting is null. - Also, provides the ``%(directory)s`` variable for the control path setting. type: string env: - name: ANSIBLE_SSH_CONTROL_PATH_DIR ini: - section: ssh_connection key: control_path_dir vars: - name: ansible_control_path_dir version_added: '2.7' sftp_batch_mode: default: true description: 'TODO: write it' env: [{name: ANSIBLE_SFTP_BATCH_MODE}] ini: - {key: sftp_batch_mode, section: ssh_connection} type: bool vars: - name: ansible_sftp_batch_mode version_added: '2.7' ssh_transfer_method: description: Preferred method to use when transferring files over ssh choices: sftp: This is the most reliable way to copy things with SSH. scp: Deprecated in OpenSSH. For OpenSSH >=9.0 you must add an additional option to enable scp C(scp_extra_args="-O"). piped: Creates an SSH pipe with C(dd) on either side to copy the data. smart: Tries each method in order (sftp > scp > piped), until one succeeds or they all fail. default: smart type: string env: [{name: ANSIBLE_SSH_TRANSFER_METHOD}] ini: - {key: transfer_method, section: ssh_connection} vars: - name: ansible_ssh_transfer_method version_added: '2.12' use_tty: version_added: '2.5' default: true description: add -tt to ssh commands to force tty allocation. env: [{name: ANSIBLE_SSH_USETTY}] ini: - {key: usetty, section: ssh_connection} type: bool vars: - name: ansible_ssh_use_tty version_added: '2.7' timeout: default: 10 description: - This is the default amount of time we will wait while establishing an SSH connection. - It also controls how long we can wait to access reading the connection once established (select on the socket). env: - name: ANSIBLE_TIMEOUT - name: ANSIBLE_SSH_TIMEOUT version_added: '2.11' ini: - key: timeout section: defaults - key: timeout section: ssh_connection version_added: '2.11' vars: - name: ansible_ssh_timeout version_added: '2.11' cli: - name: timeout type: integer pkcs11_provider: version_added: '2.12' default: "" type: string description: - "PKCS11 SmartCard provider such as opensc, example: /usr/local/lib/opensc-pkcs11.so" - Requires sshpass version 1.06+, sshpass must support the -P option. env: [{name: ANSIBLE_PKCS11_PROVIDER}] ini: - {key: pkcs11_provider, section: ssh_connection} vars: - name: ansible_ssh_pkcs11_provider Nwraps)AnsibleAuthenticationFailureAnsibleConnectionFailure AnsibleErrorAnsibleFileNotFound)PY3 text_type binary_type)to_bytes to_nativeto_text)ConnectionBaseBUFSIZE) _parse_clixml)Display) unfrackpath makedirs_safeP)s"Traceback (most recent call last):sPHP Parse error:schmod: invalid modes-chmod: A flag or octal number is not correct.z ^debug\d+: .*c@seZdZdZdS)$AnsibleControlPersistBrokenPipeErrorz ControlPersist broken pipe N)__name__ __module__ __qualname____doc__rrI/usr/local/lib/python3.10/dist-packages/ansible/plugins/connection/ssh.pyrsrremaining_retriesintcommandbytes return_tupletuple[int, bytes, bytes]no_logboolhoststrdisplayrreturnNonec Cs|dkr\|ddkr0d|}|dkrd}|r d|}t|d|t|d}t||dd vr\d }|r@d|}nt|d}d |vrVd }td||d||}|dd krd}tD]} | |dvst| |dvrxd}nqf|rd}|rd|}t|d|t|d}t|d|dkrdkrndSd}|rd|}n d|t|d}|j||ddSdS)Nsshpassrz_Invalid/incorrect username/password. Skipping remaining {0} retries to prevent account lockout:zInvalid/incorrect password:z"{0} z{0} {1})r,zsshpass error:zsshpass: invalid option -- 'P'zInstalled sshpass version does not support customized password prompts. Upgrade sshpass to use sshpass_prompt, or otherwise switch to ssh keys.Tr-Fz&Failed to connect to the host via ssh:r%) formatr rstriprrb_NOT_SSH_ERRORSrrvvv) rrr!r#r%r'msgdetails SSH_ERROR signaturerrr _handle_errorsP         r<funcBc.Callable[t.Concatenate[Connection, P], tuple[int, bytes, bytes]]cstd fd d }|S) a+ Decorator to retry ssh/scp/sftp in the case of a connection failure Will retry if: * an exception is caught * ssh returns 255 Will not retry if * sshpass returns 5 (invalid password, to prevent account lockouts) * remaining_tries is < 2 * retries limit reached self ConnectionargsP.argskwargsP.kwargsr(r"c s>t|dd}dt|d}|dp|jj}t|D]}ttt |d}|dkrH|rHt |trHt |_ dt|j dddd |d<z}z(|g|Ri|}|jjrftjd |d|jd n tjt||jd Wn=tyttt |d}|rt |trt |_ dt|j dddd |d<td |g|Ri|}Ynw||d} t| |d||jj|jW|Styttfy} zA||dkrނd |d} | dkrd} t | trd|d|| f} n d|dt| || f} tj| |jd t| WYd} ~ qd} ~ ww|S)Nreconnection_retriesr-z%s...rpassword-d simplereprsurrogate_or_strict nonstringerrorsz/rc=%s, stdout and stderr censored due to no logr3z.RETRYING BECAUSE OF CONTROLPERSIST BROKEN PIPEr,zPssh_retry: attempt: %d, ssh return code is 255. cmd (%s), pausing for %d secondszRssh_retry: attempt: %d, caught exception(%s) from cmd (%s), pausing for %d seconds)r get_optionr _play_contextrFrangetcastlistr isinstanceospipe sshpass_piper r#r'r7r%r&rr<rr Exceptionvvtimesleep) r?rArCremaining_tries cmd_summary conn_passwordattemptcmdr!repauser8r=rrwrappeds\            z_ssh_retry..wrappedN)r?r@rArBrCrDr(r"r)r=rdrrcr _ssh_retrys?recseZdZdZdZdZdXfd d ZdYd d Ze dZd[ddZ ed\ddZ ed]dd Z d^d$d%Z d_d*d+Z d`d2d3Zedad5d6Zdbdd}d}dd|DD]}d|vrd}q d|vrd}q ||fS)a Takes a command array and scans it for ControlPersist and ControlPath settings and returns two booleans indicating whether either was found. This could be smarter, e.g. returning false if ControlPersist is 'no', but for now we do it simple way. Fcss|]}|VqdSrz)lower.0arrr z3Connection._persistence_controls..scontrolpersistTs controlpathr)rcontrolpersist controlpathb_argrrr_persistence_controlsws z Connection._persistence_controlsb_argst.Iterable[bytes] explanationcCs4tjd|ddd|Df|jd||7}dS)a Adds arguments to the ssh command and displays a caller-supplied explanation of why. :arg b_command: A list containing the command to add the new arguments to. This list will be modified by this method. :arg b_args: An iterable of new arguments to add. This iterable is used more than once so it must be persistent (ie: a list is okay but a StringIO would not) :arg explanation: A text string containing explaining why the arguments were added. It will be displayed with a high enough verbosity. .. note:: This function does its work via side-effect. The b_command list has the new arguments appended. z SSH: %s: (%s)z)(css|]}t|VqdSrz)rrrrrrrz'Connection._add_args..r3N)r'vvvvvjoinr%)r?rrrrrr _add_argss( zConnection._add_argsbinary subsystem other_args bytes | strc Gsg}|dp |jj}|d}|s|rP|std|s$|r$tdt|_|ddt|jddd d g7}|d }|sD|rDd }|rP|d t|d dg7}|t|d dg7}|rp|rp| |dddddddtd|fd|dkr|dr|rddg}| ||d|ddg7}t j r| ddt j |d} | rdd| | D}| ||d|d d!urd"}| ||d#|d$|_|jd%urdd&t|jdd d f}| ||d'|d(} | rdd)ttj| d dd*f}| ||d+|s| |d,d-|d.|_|jr!| |dd/t|jd dfd0|d1} | |dd2t| d dd3fd4d5d6|fD] } || } | d%ur\d7d| | D}| ||d8| q=||\}}|rd9|_|s|d:|_t|j}t|d d}t|d;t|tjstdt|jt|d?d df}| ||d@|r|dAd|D7}|S)Ba Takes a executable (ssh, scp, sftp or wrapper) and optional extra arguments and returns the remote command wrapped in local ssh shell commands and ready for execution. :arg binary: actual executable to use to execute command. :arg subsystem: type of executable provided, ssh/sftp/scp, needed because wrappers for ssh might have diff names. :arg other_args: dict of, value pairs passed as arguments to the ssh binary rFpkcs11_providerzhto use the 'ssh' connection type with passwords or pkcs11_provider, you must install the sshpass programz6to use pkcs11_provider you must specify a password/pinr*rGrrHrIrJsshpass_promptzEnter PIN for s-PrL-oKbdInteractiveAuthentication=nos"PreferredAuthentications=publickeyPasswordAuthentication=nozPKCS11Provider=%sz Enable pkcs11sftpsftp_batch_modes BatchMode=nozdisable batch mode for sshpasss-b-vssh_argscSg|]}t|ddqSrIrr rrrr z-Connection._build_command..zansible.cfg set ssh_argshost_key_checkingF)rsStrictHostKeyChecking=noz4ANSIBLE_HOST_KEY_CHECKING/host_key_checking disabledrmNsPort=z0ANSIBLE_REMOTE_PORT/remote_port/ansible_port setprivate_key_filesIdentityFile=""zJANSIBLE_PRIVATE_KEY_FILE/private_key_file/ansible_ssh_private_key_file set)rrrsIPreferredAuthentications=gssapi-with-mic,gssapi-keyex,hostbased,publickeyrrz-ansible_password/ansible_ssh_password not setrns User="%s"z8ANSIBLE_REMOTE_USER/remote_user/ansible_user/user/-u settimeoutsConnectTimeout=)rLrKzANSIBLE_TIMEOUT/timeout setssh_common_argsz{0}_extra_argscSrrrrrrrrrzSet %sTrqizCannot write to ControlPath %srpsControlPath="%s") directoryz,found only ControlPersist; added ControlPathcSsg|]}t|qSrrrrrrr4s)rNrOrFrrrUrVrWr rr' verbosityappend_split_ssh_argsrmpath expanduserror4r _persistentrqrraccessW_OKr rprr%dict)r?rrrrr^rpassword_promptrrkeyroptattrrrcpdirb_cpdirrrr_build_commands                       zConnection._build_commandfh io.IOBasein_datar ssh_processsubprocess.Popenc Cstdz |t||Wn2ttfyD}z$td| t |dddur:t d|j t |f|dWYd}~nd}~wwtdt|dS)z Writes initial data to the stdin filehandle of the subprocess and closes it. (The handle must be closed; otherwise, for example, "sftp -b -" will just hang forever waiting for more commands.) zSending initial datagMbP? returncodeN[Data could not be sent to remote host "%s". Make sure this host can be reached over ssh: %s)orig_exczSent initial data (%d bytes))r'debugwriter closerIOErrorrZr[pollrrrr%r len)r?rrrrarrr_send_initial_data8s$      zConnection._send_initial_datarc Cs(z|WdSttfyYdSw)z& Terminate a process, ignoring errors N) terminaterrrrrr_terminate_processRs zConnection._terminate_processsourcestateb_chunksudoabletuple[bytes, bytes]c CsHg}|dD]}t|d}d}t|rnh|jr5|j|r5t d|||fd|j d<d}nK|jj rQ|j |rQt d|||fd|j d<d}n/|ri|j |rit d|||fd|j d <n|r|j|rt d |||fd|j d <|s||qd } |r|d ds|d } |dd }d || fS)ai Takes a string, extracts complete lines from it, tests to see if they are a prompt, error message, etc., and sets appropriate flags in self. Prompt and success lines are removed. Returns the processed (i.e. possibly-edited) output and the unprocessed remainder (to be processed with the next chunk) as strings. Tz Fz*become_prompt: (source=%s, state=%s): '%s' become_promptz+become_success: (source=%s, state=%s): '%s'become_successz)become_error: (source=%s, state=%s): '%s' become_errorz2become_nopasswd_error: (source=%s, state=%s): '%s'become_nopasswd_error N) splitlinesrr5 SSH_DEBUGmatchbecome expect_promptcheck_password_promptr'r_flagssuccess check_successcheck_incorrect_passwordcheck_missing_passwordrendswithr) r?rrrroutputb_line display_linesuppress_output remainderrrr_examine_output\s8        zConnection._examine_outputr` bytes | Nonecheckrcr"c! Csddd|D}tjd||jdd}t|ttfr#t|}nt t t|}| dp2|j j }|stz1t\}} trN|rNtj|| tjtj|jd}n tj|| tjtjd }t|d d } t| Wn ttfysd}Ynw|sz$tr|rtj|tjtjtj|jd}n tj|tjtjtjd }|j} Wnttfy} ztd t| d} ~ ww|rt|jd zt|jd t|dWnty} z| jtjks| dur߂WYd} ~ nd} ~ wwt|jd gd} | !d} t| d|vrB|rBt"|j#dd}|r%| !d} t$d| | t%|fn|j#rB|j#j&rB| !d} t$d| | t%|j#j&fd}}d}}t'ddddd|_(d| d}|j)|j*fD]}t++|t+j,t++|t+j-tj.Bq`t/0}|1|j)t/j2|1|j*t/j2| | dkr|r|3| ||| d 7} z | }|4|}|s| | !dkr|durn|5|td|t|f|D]U\}}|j6|j)kr|j)7}|dkr|8|j)d }||7}t$d| t%|fq|j6|j*kr |j*7}|dkr|8|j*||7}t$d| t%|fq| | !dkrU|r?|9d| | ||\}}||7}|}|rT|9d | | ||\}}||7}|}n ||7}||7}d}}| | dkr|j(d!rt$d"|j#j d#|j d$}| t|d%d&d| :d|j(d!<| d 7} n |j(d'r| d 7} | | dkr|j(d'rtd(d|j(d'<| d 7} nW|j(d)rtd*|5|d|j(d)<td+|j#j;|j(d,rtd-|5|d|j(d,<td.|j#j;|j(d!rtd/|5|d|j(d!<td+|j#j;| | dkr'|r#|3| ||| d 7} |dur9|<r4|s5nd }q|<sC|=nqW|| |j)|j*n|| |j)|j*w| d0r|d d1kr|j>d2krtd3d4|vpd5|v}|j>d kr|rtd6d7|v}|j>d8krt|} |rt?d9| |r|rt@d:|j| f|j>||fS);zL Starts the command and communicates with it until it ends.  css|] }tt|VqdSrz)shlexquoter)rcrrrrsz'Connection._bare_run..z SSH: EXEC {0}r3NrF)rrrpass_fdsrwbrz=Unable to execute ssh command line on a controller due to: %sr-r)awaiting_promptawaiting_escalation ready_to_send awaiting_exitrssh_executablepromptrzInitial state: %s: %srrF)rrrrr,rTz9Timeout (%ds) waiting for privilege escalation prompt: %sz"stdout chunk (state=%s): >>>%s<<< z"stderr chunk (state=%s): >>>%s<<< rrrz-Sending become_password in response to prompt become_pass) playcontextrIrrzEscalation succeededrzEscalation failedzIncorrect %s passwordrzEscalation requires passwordzMissing %s passwordzEscalation prompt repeatedrr*r0zUsing a SSH password instead of a key is not possible because Host Key checking is enabled and sshpass does not support this. Please add this host's fingerprint to your known_hosts file to manage this host.s(Bad configuration option: ControlPersists,unknown configuration option: ControlPersistzusing -c ssh on certain older ssh versions may not support ControlPersist, set ANSIBLE_SSH_ARGS="" (or ssh_args in [ssh_connection] section of the config file) before running agains4mux_client_hello_exchange: write packet: Broken piper1z@Data could not be sent because of ControlPersist broken pipe: %sr)Arr'r7r4r%rTr r r rSmaprNrOrFptyopenptyr rrrrWrUfdopenrrrrrr rerrnoEPIPErindexrrrrrrrrrrfcntlF_SETFLF_GETFL O_NONBLOCK selectorsDefaultSelectorregister EVENT_READrselectrfileobjread unregisterrflushnameget_mapwaitrrr)!r?r`rrr display_cmdrr^masterslaverrastatesrrb_stdoutb_stderr b_tmp_stdout b_tmp_stderrrfdselectorreventsreventrb_output b_unprocessedrcontrolpersisterrorcontrolpersist_broken_pipe additionalrrr _bare_runs`       $                                           zConnection._bare_runcCs|j||||dS)z=Wrapper around _bare_run that retries the connection )rr)r>)r?r`rrrrrr_runszConnection._runin_pathout_path sftp_actionc Csd|j}gd}t|jddr|dg}|d}|dkr#|}n|g}|D]}d} } } |dkr`||d dt|} d |t |t |} t| d d } |j | | dd \} } } n|dkr|d}|dkr~||dd||j ||} n||d|d||j |} d} |j | | dd \} } } nr|dkr|dkr|j d|j |t fdd\} } } t t|ddd }|| Wdn1swYn8t t|ddd}t|d d } Wdn1swY| sd}nd}|j d|t |f| dd\} } } | dkr| | | fSt|dkr exec_commandropenrr'rr'warningrrrr r)r?r@rArBr% smart_methodsmethodsrEmethodrrrr`rrCout_filefcountrrr_file_transport_commandsb       "  $    z"Connection._file_transport_commandrcCs(d}td|r d}d||ddfS)zA converts a Windows path to one that's supported by SFTP and SCP riz^\w{1}:/z%s%s\)rerreplace)r?rprefixrrr_escape_win_paths zConnection._escape_win_pathc stt|j|||d|dp|jj|_tjd |j |jdt |j ddrFd}dd|j j |j jg}||j j|d ddd d |}|d }|d }|s]|r]|r]d|j|f}n|j|f}|j|dg|R}|j|||d\}} } t |j ddr| drt| } || | fS)z" run a command on the remote host rMr%z&ESTABLISH SSH CONNECTION FOR USER: {0}r3rhFzchcp.com65001T)as_list strict_mode preserve_rcrruse_ttyz-ttrfrKs #< CLIXML)rjr@rOrNrOrlr%r'r7r4rorrrs_SHELL_REDIRECT_ALLNULL _SHELL_ANDextend_encode_scriptrrr? startswithr) r?r`rr cmd_partsrrcrArrrrxrrrOs$      zConnection.exec_commandcstt||||dp|jj|_tjd |||jdt j t |dds2td t|t|jddr>||}|||d S) z& transfer a file from local to remote r%zPUT {0} TO {1}r3rIrz"file or module does not exist: {0}rhFput)rjr@put_filerNrOrlr%r'r7r4rUrexistsr rr rrrsr^rXr?r@rArxrrrk?s zConnection.put_filecsdtt||||dp|jj|_tjd |||jdt |j ddr+| |}| ||dS)z# fetch a file from remote to local r%zFETCH {0} TO {1}r3rhFrJ)rjr@ fetch_filerNrOrlr%r'r7r4rrrsr^rXrmrxrrrnOs  zConnection.fetch_filecCsd}|dp |jj|_||dddd|j}tdt|tj |tj tj tj d}| \}}| }|d krFtd t|nd }|r||dddd |j}td t|tj |tj tj tj d}| \}}| }|d krt dt||dS)NFr%rrfz-Ocheckzsending connection check: %srrzNo connection to reset: %sTstopzsending connection stop: %szFailed to reset connection:%s)rNrOrlr%rr'r7rrrrrr,rQr)r? run_resetr`rrr status_coderrrreset^s&   zConnection.resetcCs d|_dS)NF) _connectedr{rrrr{s zConnection.close)rArgrCrgr(r))r(r@)NN) r%r}rmr~ror}rrrr~r(r&)r(r$)rrr(r)rrrrrr&r(r))rr&rr&rrr(r)rrrr rrr(r))rrr(r)) rr&rr&rr rr$r(r)TT) r`rrrrr$rr$r(r")r@r&rAr&rBr&r(r")rr&r(r&)NT)r`r&rrrr$r(r")r@r&rAr&r(r")r(r))rrrr transporthas_pipeliningrkr| staticmethodrrrrrrrrr>rer?rXr^rOrkrnrsr __classcell__rrrxrr@1sD        1)  F 1 r@)rrrr r!r"r#r$r%r&r'rr(r))r=r>r(r>)7 __future__r DOCUMENTATIONcollections.abcabcr rrriorUrr[r!r rrZtypingrQ functoolsransible.errorsrrrransible.module_utils.sixr r r +ansible.module_utils.common.text.convertersr r ransible.plugins.connectionrr ansible.plugins.shell.powershellransible.utils.displayransible.utils.pathrrr' ParamSpecrr6rcompilerrr<rer@rrrrsF  i      ?Q