a )g; @sddlmZmZmZeZdZddlZddlZddl Z ddl Z ddl Z ddl Z ddl mZddlmZmZddlmZddlmZmZddlmZmZmZddlmZdd lmZdd l m!Z!eZ"Gd d d eZ#dS) )absolute_importdivisionprint_functiona name: local short_description: execute on controller description: - This connection plugin allows ansible to execute tasks on the Ansible 'controller' instead of on a remote host. author: ansible (@core) version_added: historical extends_documentation_fragment: - connection_pipelining notes: - The remote user is ignored, the user with which the ansible CLI was executed is used instead. N) AnsibleErrorAnsibleFileNotFound) selectors) text_type binary_type)to_bytes to_nativeto_text)ConnectionBase)Display) unfrackpathcs^eZdZdZdZdZfddZddZdfd d Zfd d Z fd dZ ddZ Z S) Connectionz Local based connections localTcsZtt|j|i|d|_zt|_Wn*tyTt dt d|_Yn0dS)NzPCurrent user (uid=%s) does not seem to exist on this system, leaving user empty.) superr__init__cwdgetpassZgetuser default_userKeyErrordisplayZvvosgetuid)selfargskwargs __class__D/usr/lib/python3.9/site-packages/ansible/plugins/connection/local.pyr.s zConnection.__init__cCs6|j|j_|js2tjd|jj|jjdd|_|S)z/ connect to the local host; nothing to do here z(ESTABLISH LOCAL CONNECTION FOR USER: {0}hostT)r _play_contextZ remote_user _connectedrvvvformat remote_addrrr!r!r"_connect8s  zConnection._connectNc stt|j|||dtdtjr4tjdnd}tj t |ddsXt d|tj dt||jjd td t|ttfrt |}n tt |}d}tj}|r|jr|jr|d szt\}}Wn<ttfy}ztd t|WYd}~n d}~00tj |t|ttf||j!|tjtjd }|durZt"|td|jrn|jrn|rnt##|j$t#j%t##|j$t#j&tj'Bt##|j(t#j%t##|j(t#j&tj'Bt)*} | +|j$t)j,| +|j(t)j,d} z|j-| s|j.| s| /|jj0} | s@|1\} } t dt| | D]<\}}|j2|j$krf|j$3}n|j2|j(krD|j(3}qD|s|1\} } t dt| | |7} qW| "n | "0|j-| s"|jjd|jd}|dur |j45t |dddnt5|t |dddt##|j$t#j%t##|j$t#j&tj'@t##|j(t#j%t##|j(t#j&tj'@td|1|\} } td|rt"|td|j6| | fS)z! run a command on the local host )in_datasudoablezin local.exec_command()rNsurrogate_or_stricterrorsz^failed to find the executable specified %s. Please verify if the executable exists and re-try.zEXEC {0}r#zopening command with Popen()Z pipeliningzUnable to open pty: %s)shell executablerstdinstdoutstderrz!done running command with Popen()z:timeout waiting for privilege escalation password prompt: z;privilege output closed while waiting for password prompt: become_pass)Z playcontext z!getting output with communicate()zdone communicatingzdone with local.exec_command())7rr exec_commandrdebugCZDEFAULT_EXECUTABLEsplitrpathexistsr rr'r(r r%r) isinstancerr map subprocessPIPEZbecomeZ expect_promptZ get_optionptyopenptyIOErrorOSErrorr Popenrclosefcntlr4ZF_SETFLZF_GETFL O_NONBLOCKr5rZDefaultSelectorregisterZ EVENT_READZ check_successZcheck_password_promptZselecttimeoutZ communicateZfileobjreadr3write returncode)rcmdr,r-r2Zmasterr3epselectorZ become_outputZeventsr4r5keyZeventchunkr7rr!r"r9Ds    &(    $$     &&    zConnection.exec_commandc stt|||t||jd}t||jd}tjd|||jj dt j t |ddsntdt|z tt |ddt |ddWnftjytdt|t|Yn<ty}z$tdt|t|WYd }~n d }~00d S) z% transfer a file from local to local )ZbasedirzPUT {0} TO {1}r#r.r/z"file or module does not exist: {0}z(failed to copy: {0} and {1} are the samez#failed to transfer file to {0}: {1}N)rrput_filerrrr'r(r%r)rr=r>r rr shutilcopyfileErrorrrE)rin_pathout_pathrQrr!r"rVs zConnection.put_filecs<tt|||tjd|||jjd|||dS)z7 fetch a file from local to local -- for compatibility zFETCH {0} TO {1}r#N) rr fetch_filerr'r(r%r)rV)rrZr[rr!r"r\szConnection.fetch_filecCs d|_dS)z. terminate the connection; nothing to do here FN)r&r*r!r!r"rHszConnection.close)NT) __name__ __module__ __qualname____doc__Z transportZhas_pipeliningrr+r9rVr\rH __classcell__r!r!rr"r(s  b  r)$Z __future__rrrtypeZ __metaclass__Z DOCUMENTATIONrIrrrCrWrAZansible.constantsZ constantsr;Zansible.errorsrrZansible.module_utils.compatrZansible.module_utils.sixrr Zansible.module_utils._textr r r Zansible.plugins.connectionr Zansible.utils.displayrZansible.utils.pathrrrr!r!r!r"s$