HEX
Server: LiteSpeed
System: Linux kapuas.iixcp.rumahweb.net 5.14.0-427.42.1.el9_4.x86_64 #1 SMP PREEMPT_DYNAMIC Fri Nov 1 14:58:02 EDT 2024 x86_64
User: mirz4654 (1666)
PHP: 8.1.33
Disabled: system,exec,escapeshellarg,escapeshellcmd,passthru,proc_close,proc_get_status,proc_nice,proc_open,proc_terminate,shell_exec,popen,pclose,dl,pfsockopen,leak,apache_child_terminate,posix_kill,posix_mkfifo,posix_setsid,posix_setuid,posix_setpgid,ini_alter,show_source,define_syslog_variables,symlink,syslog,openlog,openlog,closelog,ocinumcols,listen,chgrp,apache_note,apache_setenv,debugger_on,debugger_off,ftp_exec,dll,ftp,myshellexec,socket_bind,mail,posix_getwpuid
Upload Files
File: //usr/lib/python3.9/site-packages/ansible/plugins/connection/__pycache__/ssh.cpython-39.pyc
a

�)gY��@s`ddlmZmZmZeZdZddlZddlZddl	Z	ddl
Z
ddlZddlZddl
Z
ddlZddlZddlmZddlmZmZmZmZddlmZddlmZddlmZmZmZdd	lmZm Z m!Z!dd
l"m#Z#m$Z$ddl%m&Z&m'Z'ddl(m)Z)dd
l*m+Z+ddl,m-Z-m.Z.e+�Z/dZ0da1e�2d�Z3Gdd�de�Z4e/fdd�Z5dd�Z6Gdd�de&�Z7dS)�)�absolute_import�division�print_functiona,5
    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:
        - Many options default to C(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
          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 check 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 C(remote_user). Can be supplied as CLI option.
          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: ''
          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'
          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.
          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 C(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.
          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 C(sftp) which will use the first binary available in $PATH.
          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 C(scp) which will use the first binary available in $PATH.
          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
          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
          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.
          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.
          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.
          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.
        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.
        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: 'yes'
        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"
            - Setting to 'smart' (default) will try them in order, until one succeeds or they all fail
            - For OpenSSH >=9.0 you must add an additional option to enable scp (scp_extra_args="-O")
            - Using 'piped' creates an ssh pipe with C(dd) on either side to copy the data
        choices: ['sftp', 'scp', 'piped', 'smart']
        env: [{name: ANSIBLE_SSH_TRANSFER_METHOD}]
        ini:
            - {key: transfer_method, section: ssh_connection}
        vars:
            - name: ansible_ssh_transfer_method
              version_added: '2.12'
      scp_if_ssh:
        deprecated:
              why: In favor of the "ssh_transfer_method" option.
              version: "2.17"
              alternatives: ssh_transfer_method
        default: smart
        description:
          - "Preferred method to use when transferring files over SSH."
          - When set to I(smart), Ansible will try them until one succeeds or they all fail.
          - If set to I(True), it will force 'scp', if I(False) it will use 'sftp'.
          - For OpenSSH >=9.0 you must add an additional option to enable scp (scp_extra_args="-O")
          - This setting will overridden by ssh_transfer_method if set.
        env: [{name: ANSIBLE_SCP_IF_SSH}]
        ini:
        - {key: scp_if_ssh, section: ssh_connection}
        vars:
          - name: ansible_scp_if_ssh
            version_added: '2.7'
      use_tty:
        version_added: '2.5'
        default: 'yes'
        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: ""
        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
N��wraps)�AnsibleAuthenticationFailure�AnsibleConnectionFailure�AnsibleError�AnsibleFileNotFound)�AnsibleOptionsError)�	selectors)�PY3�	text_type�binary_type)�to_bytes�	to_native�to_text)�BOOLEANS�boolean)�ConnectionBase�BUFSIZE)�
_parse_clixml)�Display)�unfrackpath�
makedirs_safe)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__�r r �B/usr/lib/python3.9/site-packages/ansible/plugins/connection/ssh.pyr�src
Cs�|dkr�|ddkr\d�|�}|dkr*d}|r:d�|�}nd�|t|d����}t|��nX|dd	vr�d
}|r|d�|�}n8t|d���}d|vr�d}td�||���d�||�}|dd
k�r,d}tD]$}	|	|dvs�|	|dvr�d}q�q�|�r,d}|�rd�|�}nd�|t|d����}t|��d|dk�rHdk�r�nn<d}|�rbd�|�}nd�|t|d����}|j||d�dS)N�sshpassr�z_Invalid/incorrect username/password. Skipping remaining {0} retries to prevent account lockout:zInvalid/incorrect password:z"{0} <error censored due to no log>z{0} {1}�)�r$���zsshpass error:zsshpass: invalid option -- 'P'z�Installed 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:���host)	�formatr�rstriprr	�b_NOT_SSH_ERRORSrr�vvv)
�remaining_retriesZcommand�return_tuple�no_logr,�display�msg�detailsZ	SSH_ERRORZ	signaturer r r!�
_handle_error�sH

 r7cst���fdd��}|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
    c
sJt|�d��d}dt|d�}|�d�p2|jj}t|�D�]}|d}|dkr�|r�t|t�r�t�	�|_
dt|j
dddd	�|d<z�zL�|g|�Ri|��}|jjr�t
jd
|d|jd�nt
j||jd�Wntt�yH|d}|�r$t|t��r$t�	�|_
dt|j
dddd	�|d<t
�d��|g|�Ri|��}Yn0||d}	t|	|d||jj|j�W�qFWq<t�y��Yq<ttf�yB}
z�||dk�r��nxd
|d}|dk�r�d}t|
t��r�d|d||f}nd|dt|
�||f}t
j||jd�t�|�WYd}
~
q<WYd}
~
q<d}
~
00q<|S)NZreconnection_retriesr%z%s...r�password�-d�
simplerepr�surrogate_or_strict��	nonstring�errorsz/rc=%s, stdout and stderr censored due to no logr+z.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)�int�
get_optionr�
_play_contextr8�range�
isinstance�list�os�pipe�sshpass_piperr3r4r0r,rr7rr�	ExceptionZvv�time�sleep)
�self�args�kwargsZremaining_triesZcmd_summary�
conn_passwordZattempt�cmdr2r1�e�pauser5��funcr r!�wrapped�sR



�
$z_ssh_retry.<locals>.wrappedr)rTrUr rSr!�
_ssh_retry�s?rVcs�eZdZdZdZdZ�fdd�Zdd�Zed+d	d
��Z	edd��Z
ed
d��Zdd�Zdd�Z
dd�Zedd��Zdd�Zd,dd�Zed-dd��Zedd��Zdd �Zd.�fd!d"�	Z�fd#d$�Z�fd%d&�Zd'd(�Zd)d*�Z�ZS)/�
Connectionz ssh based connections �sshTcsjtt|�j|i|��|jj|_|jj|_|jj|_d|_	d|_
t|jdd�rfd|_
d|_d|_d|_dS)N�_IS_WINDOWSFT)z.ps1z.exe�)�superrW�__init__rB�remote_addrr,�port�remote_user�user�control_path�control_path_dir�getattr�_shellZhas_native_asyncZalways_pipeline_modulesZ!module_implementation_preferencesZallow_executable)rLrMrN��	__class__r r!r\*s


zConnection.__init__cCs|S�Nr �rLr r r!�_connectAszConnection._connectNc	Csdd|||f}|r|d|7}|r2|dt|�7}t��}|�t|��|��}d|dd�}|S)z7Make a hash for the controlpath based on con attributesz%s-%s-%sz-%sz%(directory)s/N�
)r�hashlibZsha1�updaterZ	hexdigest)	r,r^r`Z
connection�pidZpstring�mZdigestZcpathr r r!�_create_control_pathDszConnection._create_control_pathcCsNtdurJz*tjdgtjtjtjd�}|��daWntyHdaYn0tS)NZsshpass��stdin�stdout�stderrTF)�SSHPASS_AVAILABLE�
subprocess�Popen�PIPE�communicate�OSError��pr r r!�_sshpass_availableRs
zConnection._sshpass_availablecCs>d}d}dd�|D�D]}d|vr(d}qd|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|]}|��VqdSrg)�lower��.0�ar r r!�	<genexpr>p�z3Connection._persistence_controls.<locals>.<genexpr>scontrolpersistTscontrolpathr )�	b_command�controlpersist�controlpathZb_argr r r!�_persistence_controlsds	z Connection._persistence_controlscCs4tjd|d�dd�|D��f|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|�VqdSrg)rr~r r r!r��r�z'Connection._add_args.<locals>.<genexpr>r+N)r4Zvvvvv�joinr,)rLr��b_argsZexplanationr r r!�	_add_argsxs
(zConnection._add_argsc
Gs�g}|�d�p|jj}|�d�}|s(|r�|��s8td��|sH|rHtd��t��|_|ddt|jddd	d
�g7}|�d�}|s�|r�d}|r�|d
t|d	d�g7}|t|d	d�g7}|r�|r�|�	|dddddddtd|�fd�|dk�r|�d��r|�rddg}|�	||d�|ddg7}t
jdk�r4|�d�|�d�}	|	�rfdd�|�
|	�D�}|�	||d �|�d!�d"u�r�d#}|�	||d$�|�d%�|_|jd&u�r�dd't|jdd	d
�f}|�	||d(�|�d)�}
|
�rdd*ttj�|
�d	d�d+f}|�	||d,�|�s|�	|d-d.�|�d/�|_|j�rL|�	|dd0t|jd	d�fd1�|�d2�}|�	|dd3t|d	dd4�fd5�d6d7�|�fD]@}|�|�}
|
d&u�r�d8d�|�
|
�D�}|�	||d9|��q�|�|�\}}|�r�d:|_|�s�|�d;�|_t|j�}t|d	d�}t|d<�t�|tj��s2td=t|���|�d>�|_|j�s\|�|j|j|j�|_dd?t|jt|d@�d	d�f}|�	||dA�|�r�|dBd�|D�7}|S)Ca�
        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

        r8�pkcs11_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"r9rr:r;r<Zsshpass_promptzEnter PIN for s-P�r>�-o�KbdInteractiveAuthentication=nos"PreferredAuthentications=publickey�PasswordAuthentication=nozPKCS11Provider=%sz
Enable pkcs11�sftpZsftp_batch_modesBatchMode=nozdisable batch mode for sshpasss-b�-r&s-vvv�ssh_argscSsg|]}t|dd��qS�r;r��rr~r r r!�
<listcomp>�r�z-Connection._build_command.<locals>.<listcomp>zansible.cfg set ssh_args�host_key_checkingF)r�sStrictHostKeyChecking=noz4ANSIBLE_HOST_KEY_CHECKING/host_key_checking disabledr^NsPort=z0ANSIBLE_REMOTE_PORT/remote_port/ansible_port setZprivate_key_filesIdentityFile="�"zJANSIBLE_PRIVATE_KEY_FILE/private_key_file/ansible_ssh_private_key_file set)r�r�r�sIPreferredAuthentications=gssapi-with-mic,gssapi-keyex,hostbased,publickeyr�r�z-ansible_password/ansible_ssh_password not setr_s	User="%s"z8ANSIBLE_REMOTE_USER/remote_user/ansible_user/user/-u set�timeoutsConnectTimeout=)r>r=zANSIBLE_TIMEOUT/timeout setZssh_common_argsz{0}_extra_argscSsg|]}t|dd��qSr�r�r~r r r!r��r�zSet %sTrbi�zCannot write to ControlPath %srasControlPath="%s")Z	directoryz,found only ControlPersist; added ControlPathcSsg|]}t|��qSr r�r~r r r!r� r�)rArBr8r|r	rFrGrHrr�r4�	verbosity�appendZ_split_ssh_argsr^�path�
expanduserr`r-r�Z_persistentrbrr�access�W_OKrraror,�dict)rLZbinaryZ	subsystemZ
other_argsr�rOr�Zpassword_promptr�r��keyr��opt�attrr�r�ZcpdirZb_cpdirr r r!�_build_command�s�

 
��

�
 �	�
�	



� zConnection._build_commandc
Cs�t�d�z|�t|��|��Wndttfy�}zHt�d�|�	�t
|dd�durttd|jt
|�f|d��WYd}~n
d}~00t�dt|��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 datag����MbP?�
returncodeN�[Data could not be sent to remote host "%s". Make sure this host can be reached over ssh: %s)Zorig_exczSent initial data (%d bytes))r4�debug�writer�closery�IOErrorrJrK�pollrcrr,r�len)rLZfh�in_dataZssh_processrQr r r!�_send_initial_data$s

��zConnection._send_initial_datac	Cs(z|��Wnttfy"Yn0dS)z& Terminate a process, ignoring errors N)Z	terminateryr�rzr r r!�_terminate_process>szConnection._terminate_processc
CsRg}|�d�D�]}t|��d�}d}t�|�r2n�|j��rl|j�|�rlt�	d|||f�d|j
d<d}n�|jjr�|j�|�r�t�	d|||f�d|j
d<d}nb|r�|j�
|�r�t�	d|||f�d|j
d	<n2|�r|j�|��rt�	d
|||f�d|j
d<|s|�|�qd}	|�rD|d
�d��sD|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_errorr�����
N)�
splitlinesrr.�	SSH_DEBUG�match�becomeZ
expect_promptZcheck_password_promptr4r��_flags�successZ
check_successZcheck_incorrect_passwordZcheck_missing_passwordr��endswithr�)
rL�source�state�b_chunk�sudoable�outputZb_lineZdisplay_lineZsuppress_outputZ	remainderr r r!�_examine_outputHs6




zConnection._examine_outputc!
Cs�d�dd�|D��}tjd�|�|jd�d}t|ttf�rFt|�}nt	t
t|��}|�d�pd|jj
}|s�zbt��\}}	tr�|r�tj||	tjtj|jd�}ntj||	tjtjd	�}t�|d
d�}
t�|	�Wnttfy�d}Yn0|�svzLt�r|�rtj|tjtjtj|jd�}ntj|tjtjtjd	�}|j}
Wn:ttf�yt}ztdt|���WYd}~n
d}~00|�rt�|jd�zt�|jd
t|�d�WnDt�y�}z*|jtjk�s�|� �du�rڂWYd}~n
d}~00t�|jd
�gd�}|�!d�}
t|�d��|v�r�|�r�t"|j#dd�}|�rf|�!d�}
t�$d||
t%|�f�n:|j#�r�|j#j&�r�|�!d�}
t�$d||
t%|j#j&�f�d}}d}}t'ddddd�|_(d|�d�}|j)|j*fD]&}t+�+|t+j,t+�+|t+j-�tj.B��q�t/�0�}|�1|j)t/j2�|�1|j*t/j2�||
dk�rV|�rV|�3|
||�|
d
7}
�zz|� �}|�4|�}|�s�|
|�!d�k�r�|du�r��q�|�5|�td|t|�f��|D]�\}}|j6|j)k�r|j)�7�}|dk�r�|�8|j)�d
}||7}t�$d|
t%|�f�nL|j6|j*k�r�|j*�7�}|dk�r:|�8|j*�||7}t�$d|
t%|�f��q�|
|�!d�k�r�|�r�|�9d||
||�\}}||7}|}|�r�|�9d||
||�\}}||7}|}n||7}||7}d}}||
dk�rV|j(d �rBt�$d!�|j#jd"|jd#�}|
�t|d$d%�d�|
�:�d|j(d <|
d
7}
n|j(d&�rV|
d
7}
||
dk�r@|j(d&�r�t�d'�d|j(d&<|
d
7}
n�|j(d(�r�t�d)�|�5|�d|j(d(<td*|j#j;��nv|j(d+�rt�d,�|�5|�d|j(d+<td-|j#j;��n:|j(d �r@t�d.�|�5|�d|j(d <td*|j#j;��||
dk�rj|�rb|�3|
||�|
d
7}
|du�r�|�<��r�|�s��q�d}�qZn|�<��sZ|�=��q��qZW|��|
��|j)��|j*��n&|��|
��|j)��|j*��0|�d/��r(|dd0k�r(|j>d1k�r(td2��d3|v�p8d4|v}|j>dk�rT|�rTtd5��d6|v}|j>d7k�r�t|�} |�r�t?d8| ��n|�r�|�r�t@d9|j| f��|j>||fS):zL
        Starts the command and communicates with it until it ends.
        � css|]}t�t|��VqdSrg)�shlex�quoter)r�cr r r!r�r�z'Connection._bare_run.<locals>.<genexpr>z
SSH: EXEC {0}r+Nr8)rqrrrsZpass_fdsrp�wbrz=Unable to execute ssh command line on a controller due to: %sr%r�)�awaiting_prompt�awaiting_escalation�
ready_to_sendZ
awaiting_exitr��ssh_executable�promptr�zInitial state: %s: %sr�r�F)r�r�r�r�r$r�z9Timeout (%ds) waiting for privilege escalation prompt: %sz"stdout chunk (state=%s):
>>>%s<<<
z"stderr chunk (state=%s):
>>>%s<<<
rrrsr�z-Sending become_password in response to prompt�become_pass)Zplaycontextr;r�r�zEscalation succeededr�zEscalation failedzIncorrect %s passwordr�zEscalation requires passwordzMissing %s passwordzEscalation prompt repeatedr�r"r(z�Using 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: ControlPersistz�using -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 piper)z@Data could not be sent because of ControlPersist broken pipe: %sr�)Ar�r4r0r-r,rDrrrrE�maprArBr8�pty�openptyr
rurvrwrHrF�fdopenr�ryr�rqr	rr��errnoZEPIPEr��indexrcr�r�rr�r�r�rrrs�fcntlZF_SETFLZF_GETFL�
O_NONBLOCKrZDefaultSelector�registerZ
EVENT_READr�Zselectr�Zfileobj�readZ
unregisterr��flush�nameZget_map�waitr�rr)!rLrPr�r��checkrcZdisplay_cmdr{rOZmasterZslaverqrQZstatesr�r�Zb_stdoutZb_stderrZb_tmp_stdoutZb_tmp_stderrr��fd�selectorr�Zeventsr�Zeventr�Zb_outputZ
b_unprocessedr�ZcontrolpersisterrorZcontrolpersist_broken_pipe�
additionalr r r!�	_bare_runysF

��
&



�$

























�
�zConnection._bare_runcCs|j||||d�S)z=Wrapper around _bare_run that retries the connection
        )r�r�)r�)rLrPr�r�r�r r r!�_run�szConnection._runcCsLd|j}gd�}t|jdd�r*|�d�g}|�d�}|�d�}|durV|dkrVd}|durt|dkrl|}q�|g}n\t|t�s�|��}|tvr�t	|dd	�}n|dkr�t
d
��|dkr�|}n|dur�dg}nd
g}|D�],}	d}
}}|	d
k�rH|�|�d�d
t|��}
d�
|t�|�t�|��}t|dd�}|j|
|dd�\}
}}�n`|	dk�r�|�d�}|dk�r�|�|dd�
||j�|��|�}
n |�|d|d�
||j�|���}
d}|j|
|dd�\}
}}n�|	dk�r�|dk�r4|jd|tfdd�\}
}}tt|dd�d��}|�|�Wd�n1�s(0Ynttt|dd�d�� }t|��dd�}Wd�n1�sn0Y|�s�d}nd}|jd|t|f|dd�\}
}}|
d k�r�|
||fSt|�d!kr�t�d"|	|f�t�d#t|��t�d#t|��q�|
d$k�r$td%|	t|�f��n$td&t|�t|�t|�t|�f��dS)'Nz[%s])r��scp�pipedrYFr��ssh_transfer_method�
scp_if_sshZsmart)�strictz0scp_if_ssh needs to be one of [smart|True|False]Tr�r�Zsftp_executablez{0} {1} {2}
Zpassthru)r=)r�Zscp_executable�getz{0}:{1}zdd if=%s bs=%s�r�r;r�zwb+�rbz count=0rZzdd of=%s bs=%s%s�r�r�rr%zS%s transfer mechanism failed on %s. Use ANSIBLE_DEBUG=1 to see detailed informationz%sr)z(Failed to connect to the host via %s: %sz'failed to transfer file to %s %s:
%s
%s)r,rcrd�removerArD�boolr}rrrr�rr-r�r�r��exec_commandr�openr�r�r�r4�warningr�rrrr	)rL�in_path�out_pathZsftp_actionr,Z
smart_methods�methodsr�r��methodr�rrrsrPr�r�Zout_file�f�countr r r!�_file_transport_command�sx









" 

,0 

�z"Connection._file_transport_commandcCs(d}t�d|�rd}d||�dd�fS)zA converts a Windows path to one that's supported by SFTP and SCP rZz^\w{1}:�/z%s%s�\)�rer��replace)rLr��prefixr r r!�_escape_win_path�szConnection._escape_win_pathcstt|�j|||d�|�d�p&|jj|_tjd�	|j
�|jd�t|jdd�r�d}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dd��r|
�d��rt|
�}
||	|
fS)z" run a command on the remote host r�r,z&ESTABLISH SSH CONNECTION FOR USER: {0}r+rYFzchcp.comZ65001T)Zas_listZstrict_modeZpreserve_rcr�r��use_ttyz-ttrXr�s	#< CLIXML)r[rWr�rArBr]r,r4r0r-r`rcrdZ_SHELL_REDIRECT_ALLNULLZ
_SHELL_AND�extendZ_encode_scriptr�r�r��
startswithr)rLrPr�r�Z	cmd_partsr�r�rMr�rrrsrer r!r�s$



zConnection.exec_commandcs�tt|��||�|�d�p"|jj|_tjd�	||�|jd�t
j�t
|dd��sdtd�	t|����t|jdd�r||�|�}|�||d	�S)
z& transfer a file from local to remote r,zPUT {0} TO {1}r+r;r�z"file or module does not exist: {0}rYFZput)r[rW�put_filerArBr]r,r4r0r-rFr��existsrr
rrcrdr�r��rLr�r�rer r!r�:s
zConnection.put_filecsdtt|��||�|�d�p"|jj|_tjd�	||�|jd�t
|jdd�rV|�|�}|�
||d�S)z# fetch a file from remote to local r,zFETCH {0} TO {1}r+rYFr�)r[rW�
fetch_filerArBr]r,r4r0r-rcrdr�r�r�rer r!rJs
zConnection.fetch_filecCsd}|�d�p|jj|_|�|�d�ddd|j�}t�dt|��tj	|tj
tj
tj
d�}|��\}}|��}|d	kr�t�d
t|��nd}|�r
|�|�d�ddd|j�}t�d
t|��tj	|tj
tj
tj
d�}|��\}}|��}|d	k�r
t�
dt|��|��dS)NFr,r�rXz-O�checkzsending connection check: %srprzNo connection to reset: %sT�stopzsending connection stop: %szFailed to reset connection:%s)rArBr]r,r�r4r0rrurvrwrxr�r�r�)rLZ	run_resetrPr{rrrsZstatus_coder r r!�resetYs&
zConnection.resetcCs
d|_dS)NF)Z
_connectedrhr r r!r�vszConnection.close)NN)TT)TT)NT)rrrrZ	transportZhas_pipeliningr\ri�staticmethodror|r�r�r�r�r�r�r�rVr�r�r�r�r�rrr��
__classcell__r r rer!rW$s>



	1
)
X
.rW)8Z
__future__rrr�typeZ
__metaclass__Z
DOCUMENTATIONr�r�rkrFr�r�r�rurJ�	functoolsrZansible.errorsrrr	r
rZansible.module_utils.compatrZansible.module_utils.sixr
rrZansible.module_utils._textrrrZ)ansible.module_utils.parsing.convert_boolrrZansible.plugins.connectionrrZ ansible.plugins.shell.powershellrZansible.utils.displayrZansible.utils.pathrrr4r/rt�compiler�rr7rVrWr r r r!�<module>s@g
8O