
    Vh                   ~   d dl mZ d dlZd dlZd dlZd dlZd dlZd dlZd dlZd dl	Z	d dl
mZmZ d dlmZ d dlmZ d dlmZmZmZmZmZ d dlmZ d dlmZmZ d d	lmZ d d
lm Z  d dl!m"Z" d dl#m$Z$m%Z%m&Z& d dl'm(Z(m)Z)m*Z* d dl+m,Z, d dl-m.Z. d dl/m0Z0 d dl1m2Z2 d dl3m4Z4m5Z5 d dl6m7Z7 d dl8m9Z9  e2       Z:d Z; G d de      Z<y)    )annotationsN)ABCabstractmethod)Sequence)	constants)AnsibleErrorAnsibleConnectionFailureAnsibleActionSkipAnsibleActionFailAnsibleAuthenticationFailure)modify_module)discover_interpreter!InterpreterDiscoveryRequiredError)ArgumentSpecValidator)UnsupportedError)_filter_non_json_lines)binary_typestring_types	text_type)to_bytes	to_nativeto_text)jsonify)__version__)resource_from_fqcr)Display)wrap_varAnsibleUnsafeText)remove_internal_keys)get_versioned_doclinkc                    t        | t              r| j                  dd       y t        | t              r!| j	                         D ]  }t        |        y t        | t        t        f      r| D ]  }t        |        y y )Nzutf-8strict)encodingerrors)
isinstancer   encodedictitems_validate_utf8_jsonlisttuple)dos     O/home/dcms/DCMS/lib/python3.12/site-packages/ansible/plugins/action/__init__.pyr)   r)   (   sm    !Y	'(3	At	 	#A"	#	Ae}	% 	#A"	# 
&    c                  X   e Zd ZdZ eg       ZdZdZdZdZ	dZ
d Zed)d       Z	 	 	 	 	 	 d*dZd+dZd,d	Zd,d
Zd,dZd,dZd Zd Zd,dZd Zd+dZd Zd Zd Zd Zd,dZd Zd+dZd Z d Z!d-dZ"d+dZ#d+dZ$d+dZ%d+dZ&d-d Z'd.d!Z(d" Z)d+d/d#Z*	 	 d0	 d/d$Z+d% Z,d1d&Z-d-d'Z.d( Z/y)2
ActionBasez
    This class is the base class for all action plugins, and defines
    code common to all actions. The base class handles the connection
    by putting/getting files and executing commands based on the current
    action in use.
    FTc                    || _         || _        || _        || _        || _        || _        d| _        d | _        d| _        g | _	        g | _
        d | _        t        | _        y )NF)_task_connection_play_context_loader_templar_shared_loader_obj_cleanup_remote_tmp_discovered_interpreter_key_discovered_interpreter_discovery_deprecation_warnings_discovery_warnings_used_interpreterdisplay_display)selftask
connectionplay_contextloadertemplarshared_loader_objs          r.   __init__zActionBase.__init__G   sj    
%)"3#(  ,0(',$/1,#% !%  r/   Nc           
        i }|dg|d<   ~| j                   j                  r.| j                  s"t        d| j                   j                  z        | j                   j
                  r.| j                  s"t        d| j                   j                  z        | j                  rt        | j                   j                  j                               }|j                  | j                        }|r=t        d| j                   j                  ddj                  t        |                  | j                  j                   j"                   | j%                         r| j'                          |S )a   Action Plugins should implement this method to perform their
        tasks.  Everything else in this base class is a helper method for the
        action plugin to do that.

        :kwarg tmp: Deprecated parameter.  This is no longer used.  An action plugin that calls
            another one and wants to use the same remote tmp for both should set
            self._connection._shell.tmpdir rather than this parameter.
        :kwarg task_vars: The variables (host vars, group vars, config vars,
            etc) associated with this task.
        :returns: dictionary of results from the module

        Implementers of action modules may find the following variables especially useful:

        * Module parameters.  These are stored in self._task.args
        zActionModule.run() no longer honors the tmp parameter. Action plugins should set self._connection._shell.tmpdir to share the tmpdirwarningz(This action (%s) does not support async.z-This action (%s) does not support check mode.zInvalid options for z: ,)r3   	async_val_supports_asyncr   action
check_mode_supports_check_moder
   _VALID_ARGS	frozensetargskeys
differencejoinr*   r4   _shelltmpdir_early_needs_tmp_path_make_tmp_path)rA   tmp	task_varsresult	task_optsbad_optss         r.   runzActionBase.runZ   s*   & ?"/ !0F9 ::(<(<#$NQUQ[Q[QbQb$bccZZ""4+D+D#$SVZV`V`VgVg$ghh !$**//"6"6"89I ++D,<,<=H'

HYHY[^[c[cdhiqdr[s(tuu""))1d6P6P6R!r/   c                   | j                   j                  j                         }t        ||||||      }|j	                  |      }	|j                  |	j                         	 |	j                  d   }
|
rC|	j                  j                  }t        |
t              rd| j                   d| }t        |      |	|fS # t        $ r d}
Y Vw xY w)aY  Validate an argument spec against the task args

        This will return a tuple of (ValidationResult, dict) where the dict
        is the validated, coerced, and normalized task args.

        Be cautious when directly passing ``new_module_args`` directly to a
        module invocation, as it will contain the defaults, and not only
        the args supplied from the task. If you do this, the module
        should not define ``mutually_exclusive`` or similar.

        This code is roughly copied from the ``validate_argument_spec``
        action plugin for use by other action plugins.
        )mutually_exclusiverequired_togetherrequired_one_ofrequired_ifrequired_byr   NzUnsupported parameters for (z
) module: )r3   rS   copyr   validateupdatevalidated_parametersr$   
IndexErrormsgr%   r   
_load_namer   )rA   argument_specrb   rc   rd   re   rf   new_module_args	validatorvalidation_resulterrorrl   s               r.   validate_argument_specz!ActionBase.validate_argument_spec   s    * **//..0)1/+##
	 &..?0EEF	%,,Q/E
 #**..C%!124T__4EZPSuU#C(( /11  	E	s   #B; ;C	C	c                    |s| j                   j                  s0| j                  | j                  j                  j
                         yy)a?  Method to perform a clean up at the end of an action plugin execution

        By default this is designed to clean up the shell tmpdir, and is toggled based on whether
        async is in use

        Action plugins may override this if they deem necessary, but should still call this method
        via super
        N)r3   rL   _remove_tmp_pathr4   rW   rX   )rA   forces     r.   cleanupzActionBase.cleanup   s8     

,,!!$"2"2"9"9"@"@A -r/   c                T    	 |j                  |      S # t        t        f$ r |cY S w xY w)z}Helper to get an option from a plugin without having to use
        the try/except dance everywhere to set a default
        )
get_optionAttributeErrorKeyError)rA   pluginoptiondefaults       r.   get_plugin_optionzActionBase.get_plugin_option   s1    	$$V,,) 	N	s    ''c                R    | j                  | j                  j                  ||      S Nr~   )r   r4   becomerA   r}   r~   s      r.   get_become_optionzActionBase.get_become_option   &    %%d&6&6&=&=vw%WWr/   c                >    | j                  | j                  ||      S r   )r   r4   r   s      r.   get_connection_optionz ActionBase.get_connection_option   s     %%d&6&6%PPr/   c                R    | j                  | j                  j                  ||      S r   )r   r4   rW   r   s      r.   get_shell_optionzActionBase.get_shell_option   r   r/   c                    | j                   j                  j                  |      }| j                  |d      }|d   dk(  ryy)NT)cmdsudoablercr   F)r4   rW   exists_low_level_execute_command)rA   pathr   r]   s       r.   _remote_file_existszActionBase._remote_file_exists   sE    %%,,T200S40H$<1r/   c                   | j                   j                  r)|j                  d      | j                   j                     }n|}|j                  d      }t	        |      dkD  rdj                  |dd       nd}t        |      }| j                  j                  D ]J  }|dk(  rd}	g d}
|d	v r%||
v r!| j                   j                  |k7  r|	d
|}n|dk(  r||
v r|	d|}|dv rY|rWt        | j                  j                  d      r7dD ]2  }||v s| j                  j                  j                  ||         ||<   4 | j                  j                  j                  ||| j                   j                         }|j"                  sN|j$                  rBt	        |j$                        dkD  r*|j$                  d   }t'        dj)                  ||            |j*                  }|sK n t'        d|z        t-               }| j/                  |       i }| j                  j0                  rd|d<   | j                  j0                  j2                  |d<   | j                  j0                  j5                  d| j6                        |d<   | j                  j0                  j5                  d| j6                        |d<   | j                  j0                  j5                  d| j6                        |d<   dD ]x  }	 t9        |||| j:                  f|t<        j>                  jA                  d|      | j                   jB                  |tE        tG        | j                  dd             d!|\  }}} n |fS # tH        $ r}tK        tM        | |jN                  |jP                  |"            | _)        d#|jN                  z  }| jR                  |d$   |<   | j                   j                  r| j                   jT                  r| jR                  |d$   |<   || _+        n,| jR                  |d   | j                   j                     d$   |<   Y d%}~Td%}~ww xY w)&zu
        Handles the loading and templating of the module code through the
        modify_module() function.
        ansible_delegated_vars.   r    z.ps1zansible.windows)zansible.builtinzansible.legacyr   )statfilerg   pingz.win_async_status)win_statwin_filewin_copyslurp_unquote)srcdestr   )collection_list   z@The module {0} was redirected to {1}, which could not be loaded.z6The module %s was not found in configured module pathsTr   become_methodbecome_user)playcontextbecome_passbecome_passwordbecome_flags)r   r   DEFAULT_MODULE_COMPRESSION	variables_remote_is_localF)r\   module_compressionasync_timeoutenvironmentremote_is_local)rN   interpreter_namediscovery_moder\   zdiscovered_interpreter_%sansible_factsN),r3   delegate_togetsplitlenrV   r   r4   !module_implementation_preferencesrN   hasattrrW   r   r8   module_loaderfind_plugin_with_contextcollectionsresolvedredirect_listr   formatplugin_resolved_pathr'   _compute_environment_stringr   namery   r5   r   r7   Cconfigget_config_valuerL   boolgetattrr   r   r   r   r   r;   delegate_factsr:   )rA   module_namemodule_argsr\   use_varssplit_module_namecollection_nameleaf_module_namemod_typewin_collectionrewrite_collection_nameskeyr]   target_module_namemodule_pathfinal_environmentbecome_kwargsdummymodule_datamodule_stylemodule_shebangidrediscovered_keys                          r.   _configure_modulezActionBase._configure_module   s   
 ::!! }}%=>tzz?U?UVH H'--c2>ABS>TWX>X#((#4Qq#9:^`-k: ((JJ (	iH 6! "3+T( $'GG'+CC

HYHY]hHh1?AQ"RK%7OOg<g-;=M"NK $'TTYd 0 0 7 7D6 b+-/3/?/?/F/F/O/OP[\_P`/aK,b ,,::SST_ai{  |F  |F  |R  |RS  SF??''C0D0D,E,I)/)=)=b)A&&'i'p'pq|  Q  (R  S  S 55KM(	iP W[fghh !F(():;""&*M(#-1-=-=-D-D-I-IM/*+/+;+;+B+B+M+MmZ^ZlZl ,N ,nM-(/3/?/?/F/F/Q/QR_^b^p^p 0R 0rM+,,0,<,<,C,C,N,N~[_[m[m -O -oM.)  "	PE!P>KKYdfqsw  tA  tA ?]V^_`_g_g_x_x  zV DM `y `NZ^ZdZdZnZnXi\`ahimiyiy  |N  PU  bV  ]W?] O\?];lN "	PH nk;GG3 5 P/@AU%)%:%:#'#6#6&	B( 0), "=t?T?T!T =A<X<X).9
 zz--1J1JAEA]A]Io.~>7ED4sw  tP  tPI67

8N8NOP_`aop/Ps   1A4M..	Q7CQQc           	     r   t               }| j                  j                  | j                  j                  }t        |t              s|g}|D ]j  }|t        |      dk(  r| j                  j                  |      }t        |t               st        d|dt        |      d      |j                  |       l t        |      dkD  r| j                  j                  |      }t        |t               r!|j                          |j                  |        | j                  j                  j                  di |S )zZ
        Builds the environment string to be used when executing the remote task.
        r   z+environment must be a dictionary, received z () )r'   r3   r   r%   r*   r   r7   templater   typeri   clearr4   rW   
env_prefix)rA   raw_environment_outr   environmentsr   temp_environments         r.   r   z&ActionBase._compute_environment_stringL  s+   
 !F::!!-::11LlD1 ,~
  , ;&#k*:a*?#'==#9#9+#F !"2D9&_oqu  wG  rH  (I  J  J "(()9:;  !A% $ 6 67H I)40%%'&&'891t&&11F4EFFr/   c                    t        | dd      S )z[
        Determines if a tmp path should be created before the action is executed.
        TRANSFERS_FILESF)r   rA   s    r.   rY   z ActionBase._early_needs_tmp_pathm  s    
 t.66r/   c                   	 | j                   j                  d      }| j                   j                  }| j                   j                  r | j                   j                  j                  nddk7  }| j                   j                  |xs ||dk(  t        j                   | xs ||g}t        |      S # t        t        t        f$ r | j
                  j                  }Y w xY w)zE
        Determines if we are required and can do pipelining
        
pipeliningr   sunew)r4   ry   r{   rz   
ValueErrorr5   r   always_pipeline_modulesr   r   has_pipeliningr   DEFAULT_KEEP_REMOTE_FILESall)rA   r   
wrap_async
is_enabledalways_pipelinebecome_exception
conditionss          r.   _is_pipelining_enabledz!ActionBase._is_pipelining_enabledt  s    
	7))44\BJ **BB =A<L<L<S<SD,,3388Y[`dd ++)/E!+++N-o

 :+ .*5 	7++66J	7s   B0 0*CCc                (    | j                  ddg      S )zh
        Returns a list of admin users that are configured for the current shell
        plugin
        admin_usersroot)r   r   s    r.   _get_admin_userszActionBase._get_admin_users  s     $$]VH==r/   c           
        |j                  di       j                  d|j                  d|j                  dd                  }dD ]   }	 | j                  j                  |      } |S  | j                  j
                  }|S # t        $ r Y Fw xY w)z= consistently get the 'remote_address' for the action plugin delegated_varsansible_hostinventory_hostnameN)remote_addrhost)r   r4   ry   r{   r5   r  )rA   tvarsr  	variations       r.   _get_remote_addrzActionBase._get_remote_addr  s    ii 0"599.%))Tbdidmdm  oC  EI  eJ  KK  L0 	9I"..99)D  	9 ,,88K  s   	B  	BBc                   d}	 | j                   j                  d      }|S # t        $ r3 t        | j                   dd      xs | j                  j
                  }Y |S t        $ r | j                  j
                  }Y |S w xY w)z: consistently get the 'remote_user' for the action plugin Nremote_userdefault_user)r4   ry   r{   r   r5   r  rz   )rA   r  s     r.   _get_remote_userzActionBase._get_remote_user  s     	9**55mDK   	l!$"2"2NDIkTM_M_MkMkK   	9,,88K	9s   ! 8A>A>=A>c                    | j                   j                  sy| j                         }| j                         }| j	                  d      }t        |xr |||gz   v      S )z}
        The user is not the same as the connection user and is not part of the
        shell configured admin users
        Fr   )r4   r   r   r  r   r   )rA   r   r  r   s       r.   _is_become_unprivilegedz"ActionBase._is_become_unprivileged  s`     && ++-++-,,];KRK{k]7R$RSSr/   c                F   t        | j                  dd      rt        j                  }n$| j	                  | j                  dd      d      }| j                         }| j                  j                  j                         }| j                  j                  j                  |||      }| j                  |d      }|d   d	k7  r|d   d
k(  rd}n[|d   dk(  r<| j                  j                  dv r$t        j                  dkD  rd|d   |d   }nd}nd|d   v r|d   }n
d||d   fz  }d|v r|d   dk7  r|d|d   z  z   }t        j                  dkD  rd|v r|d   dk7  r|d|d   z  z  }t        |      d| _        	 |d   j!                         j#                  d|z  d      }| j                  j                  j%                  |d   d      j'                         d   }	|	dk(  rt+        d|d|d      |	| j                  j                  _        |	S # t(        $ r d}	Y Aw xY w) zE
        Create and return a temporary path on a remote box.
        r   F
remote_tmp~/.ansible/tmpr   r   )basefilesystemrX   r   r      zAuthentication failure.   )ssh   z2SSH encountered an unknown error. The output was:
stdoutstderrzSSH encountered an unknown error during the connection. We recommend you re-run the command using -vvvv, which will enable SSH debugging output to help diagnose the issuezNo space left on devicea5  Failed to create temporary directory. In some cases, you may have been able to authenticate and did not have permissions on the target directory. Consider changing the remote tmp path in ansible.cfg to a path rooted in "/tmp", for more error information use -vvv. Failed command was: %s, exited with result %dr   z, stdout output: %sz, stderr output: %sTz%s=r   r   /z2failed to resolve remote temporary directory from z: `z` returned empty string)r   r4   r   DEFAULT_LOCAL_TMP_remote_expand_userr   r  rW   _generate_temp_dir_namemkdtempr   	transportr?   	verbosityr	   r9   stripr   	join_path
splitlinesrk   r   rX   )
rA   r  rX   become_unprivilegedr  r   r]   outputstdout_partsr   s
             r.   rZ   zActionBase._make_tmp_path  s{    4##%7?((F --d.C.CLZj.C.kv{-|F"::<##**BBD%%--xH[dj-k00u0E $<1d|q 2$)9)9)C)Cx)O$$q([abj[kmst|m}~FSF ,vh/??)J NQRXY]R^L_` 6!fX&6#&="86(;K"KK  1$V);x@PTW@W06(3CCC*622'+D$	!(+11399%(:JANL!!((22<3CSITTVWYZB 9u}  @C   D  E  E)+&	  	B	s   >A H H H c                T    |xr% | j                   xr t        j                   xr d|v S )zLDetermine if temporary path should be deleted or kept by user request/configz-tmp-)r9   r   r   )rA   tmp_paths     r.   _should_remove_tmp_pathz"ActionBase._should_remove_tmp_path  s-    pD44pQ=X=X9Xp]dhp]ppr/   c           	        |@| j                   j                  j                  r | j                   j                  j                  }|s| j                  |      r| j                   j                  j	                  |d      }| j                  |d      }|j                  dd      dk7  r<t        j                  d|j                  d      d	|j                  d
d      d       yd| j                   j                  _        yy)z$Remove a temporary path we created. NT)recurseFr  r   r   z+Error deleting remote temporary files (rc: z
, stderr: r  zNo error string available.z}))	r4   rW   rX   r+  remover   r   r?   rJ   )rA   r*  rv   r   
tmp_rm_ress        r.   ru   zActionBase._remove_tmp_path  s      0 0 7 7 > >''..55HD00:""))0040HC 88u8MJ~~dA&!+#->>$#7Rn9o!q r 26  ''. ;r/   c                >    | j                   j                  ||       |S )a  
        Copy a file from the controller to a remote path

        :arg local_path: Path on controller to transfer
        :arg remote_path: Path on the remote system to transfer into

        .. warning::
            * When you use this function you likely want to use use fixup_perms2() on the
              remote_path to make sure that the remote file is readable when the user becomes
              a non-privileged user.
            * If you use fixup_perms2() on the file and copy or move the file into place, you will
              need to then remove filesystem acls on the file once it has been copied into place by
              the module.  See how the copy module implements this for help.
        )r4   put_file)rA   
local_pathremote_paths      r.   _transfer_filezActionBase._transfer_file  s      	!!*k:r/   c                   t        |t              rt        |      }t        j                  t
        j                        \  }}t        j                  |d      }	 t        |d      }|j                  |       |j                          |j                          	 | j!                  ||       t        j"                  |       |S # t        $ r}t        dt        |      z        d}~ww xY w# t        j"                  |       w xY w)zJ
        Copies the module data out to the temporary module path.
        )dirwbsurrogate_or_strictr$   z>failure writing module data to temporary file for transfer: %sN)r%   r'   r   tempfilemkstempr   r  osfdopenr   write	Exceptionr   r   flushcloser4  unlink)rA   r3  dataafdafileafoes          r.   _transfer_datazActionBase._transfer_data/  s    
 dD!4=D%%!*=*=>
UiiT"	pD)>?DIIdO 						{3IIe  	p_bklmbnnoo	p IIes$   C C* 	C'C""C'*Dc           	        || j                         }t        | j                  j                  dd      r|S | j	                         sH|rD| j                  |d      }|d   dk7  r*t        dj                  |d   t        |d                     |S | j                  d	      }|r'd
}d}dj                  |      }dj                  |      }	n&d}d}dj                  |      }dj                  |      }	| j                  |||      }|d   dk(  r|S |rD| j                  |d      }|d   dk7  r*t        dj                  |d   t        |d                     | j                  ||      }|d   dk(  r|S || j                         v rt        d      	 | j                  |gt        |      z   d      }|d   dk(  r|S | j                  ||	      }|d   dk(  r|S t        d      }| j!                  d      }|f| j#                  ||      }|d   dk(  rL| j!                  d      rt$        j'                  d|z         |rd}nd}| j                  ||      }|d   dk(  r|S | j!                  d      rat$        j'                  d|z         | j                  |d|z        }|d   dk(  r|S t        dj                  |d   t        |d                     t        d|d   dt        |d         d |d!      # t        $ r}
Y d}
~
Ed}
~
ww xY w)"a%	  
        We need the files we upload to be readable (and sometimes executable)
        by the user being sudo'd to but we want to limit other people's access
        (because the files could contain passwords or other private
        information.  We achieve this in one of these ways:

        * If no sudo is performed or the remote_user is sudo'ing to
          themselves, we don't have to change permissions.
        * If the remote_user sudo's to a privileged user (for instance, root),
          we don't have to change permissions
        * If the remote_user sudo's to an unprivileged user then we attempt to
          grant the unprivileged user access via file system acls.
        * If granting file system acls fails we try to change the owner of the
          file with chown which only works in case the remote_user is
          privileged or the remote systems allows chown calls by unprivileged
          users (e.g. HP-UX)
        * If the above fails, we next try 'chmod +a' which is a macOS way of
          setting ACLs on files.
        * If the above fails, we check if ansible_common_remote_group is set.
          If it is, we attempt to chgrp the file to its value. This is useful
          if the remote_user has a group in common with the become_user. As the
          remote_user, we can chgrp the file to that group and allow the
          become_user to read it.
        * If (the chown fails AND ansible_common_remote_group is not set) OR
          (ansible_common_remote_group is set AND the chgrp (or following chmod)
          returned non-zero), we can set the file to be world readable so that
          the second unprivileged user can read the file.
          Since this could allow other users to get access to private
          information we only do this if ansible is configured with
          "allow_world_readable_tmpfiles" in the ansible.cfg. Also note that
          when ansible_common_remote_group is set this final fallback is very
          unlikely to ever be triggered, so long as chgrp was successful. But
          just because the chgrp was successful, does not mean Ansible can
          necessarily access the files (if, for example, the variable was set
          to a group that remote_user is in, and can chgrp to, but does not have
          in common with become_user).
        N_IS_WINDOWSFzu+rwxr   r   z=Failed to set permissions on remote files (rc: {0}, err: {1})r  r   rxzr-xz{0} allow read,executezA+user:{0}:rx:allowrXzr-Xz{0} allow readzA+user:{0}:r:allowzLFailed to set file mode or acl on remote temporary files (rc: {0}, err: {1})zFailed to change ownership of the temporary files Ansible (via chmod nor setfacl) needs to create despite connecting as a privileged user. Unprivileged become user would be unable to read the file.z+az2playbook_guide/playbooks_privilege_escalation.htmlcommon_remote_groupworld_readable_tempa  Both common_remote_group and allow_world_readable_tmpfiles are set. chgrp was successful, but there is no guarantee that Ansible will be able to read the files after this operation, particularly if common_remote_group was set to a group of which the unprivileged become user is not a member. In this situation, allow_world_readable_tmpfiles is a no-op. See this URL for more details: %s#risks-of-becoming-an-unprivileged-userzg+rwxzg+rwzUsing world-readable permissions for temporary files Ansible needs to create when becoming an unprivileged user. This may be insecure. For information on securing this, see %s#risks-of-becoming-an-unprivileged-userza+%sz;Failed to set file mode on remote files (rc: {0}, err: {1})zqFailed to set permissions on the temporary files Ansible needs to create when becoming an unprivileged user (rc: z, err: z0}). For information on working around this, see z'#risks-of-becoming-an-unprivileged-user)r  r   r4   rW   r  _remote_chmodr   r   r   r   _remote_set_user_facl_remote_chownr   r*   r   r    r   _remote_chgrpr?   rJ   )rA   remote_pathsr  executeresr   
chmod_modesetfacl_modechmod_acl_modeposix_acl_moderG  become_linkgroup
group_modes                 r.   _fixup_perms2zActionBase._fixup_perms2I  s   L //1K 4##**M5A   ++- ((w?t9>&..4fI%c(m4/67 7
   ,,]; J L5<<[IN 399+FNJ !L-44[AN188EN ((
 t9>
 $$\7;C4yA~"**0&D	!#h-0+23 3   {;t9> $//11 	$$$n%5\8J%JDQC 4yA~##   ~>t9> ,,`a %%&;<$$\59C4yA~(()>?OO	B EP	P
Q !(J!'J((zBt9>''   !67 OO: =HHI
 $$\6J3FGC4yA~##&&,fIc(m,'./ / 
 D	#h-(+78 	8e , 	 	s   K* *	K>9K>c                x    | j                   j                  j                  ||      }| j                  ||      }|S )z.
        Issue a remote chmod command
        r  )r4   rW   chmodr   )rA   pathsmoder   r   rU  s         r.   rO  zActionBase._remote_chmod$  <     %%++E48--cH-E
r/   c                x    | j                   j                  j                  ||      }| j                  ||      }|S )z.
        Issue a remote chown command
        r  )r4   rW   chownr   )rA   r`  userr   r   rU  s         r.   rQ  zActionBase._remote_chown,  rb  r/   c                x    | j                   j                  j                  ||      }| j                  ||      }|S )z.
        Issue a remote chgrp command
        r  )r4   rW   chgrpr   )rA   r`  r[  r   r   rU  s         r.   rR  zActionBase._remote_chgrp4  s<     %%++E59--cH-E
r/   c                z    | j                   j                  j                  |||      }| j                  ||      }|S )z0
        Issue a remote call to setfacl
        r  )r4   rW   set_user_faclr   )rA   r`  re  ra  r   r   rU  s          r.   rP  z ActionBase._remote_set_user_facl<  s>     %%33E4F--cH-E
r/   c                   |t         j                  d       ~t        |||dd      }| j                  d||dd      }|j	                  d      rH|j	                  d	      }|s|j	                  d
      }|s|j	                  d      }t        d|d|      |d   d   sd|d   d<   d|d   vrd|d   d<   |d   S t        |d   d   t              st        dt        |d   d         z        |d   S )z3
        Get information from remote file.
        z_execute_remote_stat no longer honors the tmp parameter. Action plugins should set self._connection._shell.tmpdir to share the tmpdirFsha1)r   followget_checksumget_sizechecksum_algorithmzansible.legacy.statT)r   r   r\   r   ignore_unknown_optsfailedmodule_stderrmodule_stdoutrl   z*Failed to get information on remote file (z): r   r   1checksumr   zDInvalid checksum returned by stat: expected a string type but got %s)	r?   rJ   r'   _execute_moduler   r   r%   r   r   )	rA   r   all_varsrl  r[   ru  r   mystatrl   s	            r.   _execute_remote_statzActionBase._execute_remote_statD  sH    ?OO * + !%
 %%2GU`lt16D & R ::h**_-Cjj1jj'VZ\_`aaf~h'),F6N:& VF^+)+F6N:& f~ F6N:6Eehlmstzm{  }G  nH  iI   I  J  Jf~r/   c                   |j                  d      s|S |j                  t        j                  j                  d      }|d   }|dk(  r`| j                  d      }t        | j                  dd      rn7|r| j                  j                  r|rd|z  }nd| j                         xs dz  }| j                  j                  j                  |      }| j                  |d	      }	 |d
   j                         j                         d   }	|	s]| j                  j                  j!                         }| j                  |d	      j#                  d
d      j                         }
|
r|
}n>|}n;t%        |      dkD  r+ | j                  j                  j&                  |	g|dd  }n|	}dt        j                  j)                  |      j                  d      v rt+        d| j-                  i       z        |S # t        $ r d}	Y w xY w)zK takes a remote path and performs tilde/$HOME expansion on the remote host ~r   r   r   r   Fz~%sr   r  r  r   Nz..r  zE'%s' returned an invalid relative home directory path containing '..')
startswithr   r<  r   sepr   r   r4   r   r  rW   expand_userr   r#  r%  rk   pwdr   r   r$  dirnamer   r	  )rA   r   r   pathsep
split_pathexpand_pathr   r   rC  initial_fragmentr  expandeds               r.   r  zActionBase._remote_expand_usern  s    s#K ZZQ/
 m# 00?Kt'');UCd..55+#k1 $t'<'<'>'D"E %%11+>..sU.C	$#H~335@@B2F   ""))--/C11#1FJJ8UWX^^`C_q 8t''..889I[JWXWYN[H'H277??8,22377fimi~i~  @B  jC   C  D  D+  	$#	$s   !$G. .G<;G<c                r    |j                         j                  d      rt        j                  dd|      }|S )zC
        Removes the BECOME-SUCCESS message from the data.
        zBECOME-SUCCESS-z"^((\r)?\n)?BECOME-SUCCESS.*(\r)?\nr   )r#  r|  resub)rA   rC  s     r.   _strip_success_messagez!ActionBase._strip_success_message  s1     ::<""#4566?TJDr/   c                   | j                   j                  r| j                  st        d      d|d<   nd|d<   t        j
                  j                  d|      }| j                   j                  xs ||d<   t        j                  |d<   | j                   j                  |d	<   t        j                  |d
<   t        |d<   ||d<   |j                  dt        j                        |d<   t        j                  |d<   t        j                   |d<   t#        | j$                  d      |d<   |d   s|j                  d      |d<   | j&                  j(                  |d<   t        j*                  |d<   | j-                         rd |d<   n#| j$                  j.                  j0                  |d<   | j3                  dd      |d<   ||d<   t        j
                  j                  d|      |d<   y )Nz.check mode is not supported for this operationT_ansible_check_modeFDEFAULT_NO_TARGET_SYSLOGr   _ansible_no_log_ansible_debug_ansible_diff_ansible_verbosity_ansible_version_ansible_module_nameansible_syslog_facility_ansible_syslog_facility_ansible_selinux_special_fs!_ansible_string_conversion_actionsocket_path_ansible_socketansible_socket_ansible_shell_executable_ansible_keep_remote_files_ansible_tmpdirr  r  r   _ansible_remote_tmp_ansible_ignore_unknown_optsTARGET_LOG_INFO_ansible_target_log_info)r3   rO   rP   r   r   r   r   no_logDEFAULT_DEBUGdiffr?   r"  r   r   DEFAULT_SYSLOG_FACILITYDEFAULT_SELINUX_SPECIAL_FSSTRING_CONVERSION_ACTIONr   r4   r5   
executabler   r  rW   rX   r   )rA   r   r   r\   rp  no_target_syslogs         r.   _update_module_argszActionBase._update_module_args  s    ::  ,,"#STT15K-.16K-. 88445O[d4e)-):):)N>N%& )*$% (,zzO$ -4,=,=() +6&' /:*+ 3<--@Y[\[t[t2u./ 675Q5Q12 <=;U;U78 *11A1A=)Q%&,--6]];K-LK)* 483E3E3P3P/0 564O4O01 '')-1K)*-1-=-=-D-D-K-KK)* .2-B-B<Yi-B-j)* 7J23 34((2K2KL]ir2K2s./r/   c	           	     :   |t         j                  d       ~|t         j                  d       ~| j                  j                  j                  }	| j                  d|      s2|	0| j                          | j                  j                  j                  }	|
t               }|| j                  j                  }|| j                  j                  }| j                  ||||       d}
|s| j                  j                  rY| j                  dd      }t        | j                  j                        }
| j                  j                  j!                  d	|i       | j#                  |||
      \  }}}}t         j%                  d|z         |s|dk7  rt'        d|z        || _        d}| j                  ||      s|	0| j                          | j                  j                  j                  }	| j                  j                  j+                  |      }| j                  j                  j-                  |	d|z        }d}|dv r&| j                  j                  j-                  |	d      }|s|dk7  rt         j/                  d|z         |dk(  r| j1                  ||       n| j3                  ||       |dk(  rTd}|j5                         D ],  \  }}||dt7        j8                  t;        |            dz  }. | j3                  ||       n)|dv r%| j3                  |t=        j>                  |             t         j/                  d       | jA                         }|
| j                  j                  |
= g }|	r|r|	|g}|r|j!                  |       d}d}d}|ro| j                  jB                  sX| j#                  dt               |
      \  }}}}| j                  j                  j+                  |      }| j                  j                  j-                  |	|      }| j3                  ||       |j!                  |       | j                  j                  } dtE        jF                  d       }!|jI                  dd      jK                         }"|"||!| |g}#|r|#jM                  d|       |r|#j!                  |       n|#j!                  d       | jO                  |	      s|#j!                  d       djQ                  d  |#D              }nb| j                  |      r|}t         j%                  d!       n|}| j                  j                  jS                  ||||"      jK                         }|r2|D $cg c]  }$|$s|$	 }}$| jU                  || jW                                | jY                  |||#      }%| j[                  |%      }&|&j]                  d$d%      rd%| _/        d&|&v rFta        |&d&   tb              rta        |&d&   td              r |&d&   |&d'<   |&d&= t         j                  d(       tg        |&       |r d| j                  j                  _        d|&d)<   d*|&v r-d+|&vr)|&ji                  d*d      xs d}'|'jk                         |&d+<   d,|&v r-d-|&vr)|&ji                  d,d      xs d}'|'jk                         |&d-<   | jl                  r2|&ji                  d.      i |&d.<   | jn                  |&d.   | jl                  <   | jp                  r4|&ji                  d/      g |&d/<   |&d/   js                  | jp                         | jt                  r4|&ji                  d0      g |&d0<   |&d0   js                  | jt                         tw        |&      }&t         j/                  d1|d2|d3       |&S c c}$w )4zE
        Transfer and run a module along with its arguments.
        Nz_execute_module no longer honors the tmp parameter. Action plugins should set self._connection._shell.tmpdir to share the tmpdirz_execute_module no longer honors the delete_remote_tmp parameter. Action plugins should check self._connection._shell.tmpdir to see if a tmpdir existed before they were called to determine if they are responsible for removing it.r   )rp  	async_dirz~/.ansible_asyncr   ANSIBLE_ASYNC_DIR)r   r   r\   zUsing module file %sbinaryz'module (%s) is missing interpreter linezAnsiballZ_%s)oldnon_native_want_jsonr  rS   z transferring module to remote %sr  r   = )r  r  z"done transferring module to remoteTzansible.legacy.async_wrapperjl   J)z#!r   _z-preserve_tmpc              3  2   K   | ]  }t        |        y wN)r   ).0xs     r.   	<genexpr>z-ActionBase._execute_module.<locals>.<genexpr>p  s     9!71:9s   zPipelining is enabled.)arg_path)r   in_data_ansible_suppress_tmpdir_deleteFresultsansible_module_resultszSFound internal 'results' key in module return, renamed to 'ansible_module_results'.changedr  stdout_linesr  stderr_linesr   warningsdeprecationszdone with _execute_module (z, r   )<r?   rJ   r4   rW   rX   r   rZ   r'   r3   rN   rS   r  rL   r   r   r   appendr   vvvr   r>   get_remote_filenamer$  debugr4  rH  r(   shlexquoter   jsondumpsr   r   secrets	randbelowreplacer#  insertr+  rV   build_module_commandr]  r  r   _parse_returned_datapopr9   r%   r   r   r   r   r%  r:   r;   r=   extendr<   r   )(rA   r   r   r[   r\   persist_filesdelete_remote_tmpr   rp  rX   remove_async_dirr  r   shebangr   r   remote_module_pathremote_module_filenameargs_file_path	args_datakvenvironment_stringremote_filesr   r  r   async_module_styleasync_module_dataasync_module_pathasync_module_remote_filenameremote_async_module_pathasync_limit	async_jidinterpreter	async_cmdr  rU  rC  txts(                                           r.   rv  zActionBase._execute_module  sh   
 ?OO ] ^(OO H I !!((// **5*=&.!%%,,33FI **++K**//K  k9Zm n----kCU-VI"4::#9#9:JJ""))+>	*JK =A<R<R_j  yD  PY<R  =Z9w[*[89<83H;VWW!(!**<D~##%))0077%)%5%5%<%<%P%PQ\%]"!%!1!1!8!8!B!B6>\rKr!sDD!--44>>vvNN!6MM<?QQRx'##K1CD##$6Du$ 	'--/ KDAqQIaL0I!JJIK##NI>!CC##NDJJ{4KLMM>?!==? '

&&'78("$67L/d..FFRVRhRh:Zc Si SeO*;=N+/+;+;+B+B+V+VWh+i('+'7'7'>'>'H'HQm'n$ 8:KL 89**..KG--l;<=I "//$399;K$&>	;XjkI!  $67  0   %//7  1((9y99C **<8%45(""))>>?QSZ\_jx>y  BC '39!qA9L9|T-B-B-DE --cHg-V ((- 885u=',D$ ji(&KzZ^_hZikwOx-1)_D)*YOOqr 	T" .2D##* #DO td :((8T*1cC#&>>#3D td :((8T*1cC#&>>#3D  ++xx(0(*_%FJFbFbD!$"B"BC##xx
#+#%Z ##D$<$<=//xx'/')^$ ''(L(LM ~k;WX :s   ,^4^c                   	 t        |j                  dd      d      \  }}|D ]  }t        j                  |        t	        j
                  |      }t        j                  r|j                  dd       s	 t        |       d|d<   |S # t        $ r< t        d| j                  j                  xs | j                  j                   d      w xY w# t        $ r}t        dd	
      }|j                  dd      |d<   d|v r$|d   |d<   |d   j!                  d      r|d   |d<   d|vr|d   j!                  d      r|d   |d<   d| |d<   | j"                  st%        j&                  | j"                  j)                  d            }t%        j*                  d|z        }|j-                  |d         s|j-                  |d         rd|d<   |dxx   dz  cc<   d|v r|d   |d<   Y d }~|S d }~ww xY w)Nr  r   T)objects_only_ansible_trusted_utf8zModule "z/" returned non UTF-8 data in the JSON response._ansible_parsedF)rq  r  rs  r  rr  	Traceback	exceptionzMODULE FAILURE: rl   z!#z+%s: (?:No such file or directory|not found)zQThe module failed to execute correctly, you probably need to set the interpreter.z&
See stdout/stderr for the exact errorr   )r   r   r?   rJ   r  loadsr   MODULE_STRICT_UTF8_RESPONSEr  r)   UnicodeEncodeErrorr   r3   resolved_actionrN   r'   r|  r>   r  escapelstripcompilesearch)	rA   rU  filtered_outputr  wrC  rG  r  matchs	            r.   r  zActionBase._parse_returned_data  s   ,	'(>swwxQT?Udh(i%OX #"# ::o.D,,TXX>UW[5\'- '+D"#: G * $"4::#=#=#RARAR"S T- -   	'tU;D$'GGHc$:D!3(+H_%x=++L9(+HD% $&4+@+K+KL+Y$($9[! -QC0DK %%1 ii(>(>(E(Ed(KL

#PS^#^_<<_ 56%,,tOG\:]"uDK KDDKs{ YT
9	's2   A3C 6B C ACC 
G/D
G**G/c                   t         j                  d       |rAt         j                  d|z         | j                  j                  j	                  d|z  |      }|r|| j                  j                  _        | j                         }| j                  d      }|r| j                  j                  rt        | j                  j                        dk7  rqt        j                  s||k7  st        ||f      sOt         j                  d       | j                  j                  j                  || j                  j                        }| j                  j                  r[|<| j                   j
                  }| j                  j                  j	                  |d      }|r|dz   t#        j$                  |      z   }t         j                  d	|       | j                  j                  d
k(  r4t'        | j(                  j+                         d      | j                  _        | j                  j/                  |||      \  }	}
}t1        |
t2              rt5        |
|      }n=t1        |
t6              s+t5        dj9                  |
j;                               |      }n|
}t1        |t2              rt5        ||      }n=t1        |t6              s+t5        dj9                  |j;                               |      }n|}|	d}	| j=                  |      }t         j                  d|	||fz         t?        |	||jA                         ||jA                               S )a7  
        This is the function which executes the low level shell command, which
        may be commands to create/remove directories for temporary files, or to
        run the module code or python directly when pipelining.

        :kwarg encoding_errors: If the value returned by the command isn't
            utf-8 then we have to figure out how to transform it to unicode.
            If the value is just going to be displayed to the user (or
            discarded) then the default of 'replace' is fine.  If the data is
            used as a key or is going to be written back out to a file
            verbatim, then this won't work.  May have to use some sort of
            replacement strategy (python3 could use surrogateescape)
        :kwarg chdir: cd into this directory before executing the command.
        z&_low_level_execute_command(): startingzA_low_level_execute_command(): changing cwd to %s for this commandzcd %sr   network_cliz;_low_level_execute_command(): using become for this commandzsleep 0z -c z)_low_level_execute_command(): executing: localr8  r9  )r  r   r/   r   z>_low_level_execute_command() done: rc=%d, stdout=%s, stderr=%s)r   r  r  r  r  )!r?   r  r4   rW   append_commandr  r  r   r   r   r!  r   BECOME_ALLOW_SAME_USERanybuild_become_commandallow_executabler5   r  r  r   r6   get_basedircwdexec_commandr%   r   r   r   rV   	readlinesr  r'   r%  )rA   r   r   r  r  encoding_errorschdirruserbuserr   r  r  outerrs                 r.   r   z%ActionBase._low_level_execute_command  s     	>? MM]`eef""))885#NC 1;D##.%%'&&}5))00"4#3#3#=#=>-O))eunCPUDWMMWX""))>>sDDTDTD[D[\C,,!!//::
 &&--<<S)L 6)EKK,<<sLM %%0#+DLL,D,D,FOd#eD !--::3Zb:cFF fk*&9CFI.#((6#3#3#56OCCfk*&9CFI.#((6#3#3#56OCC:B ))#.W[]_bdgZhhir#CNN4DS_b_m_m_oppr/   c                   i }t         j                  d       | j                  dt        |d      |d      }|j	                  dd      rVt         j                  dt        j                  j                  |      d	|d
t        |j	                  dd                   |S |j	                  dd      dk(  r|j	                  d      dv rd|d<   n|j	                  d      rd|d<   n|j	                  d      r=t        j                  dkD  r*|d   t        j                  kD  rt        j                  |d<   nt         j                  d|z         | j                  dt        |      |d      }d|v rM|d   }	|d   dk(  rt        j                  |	      }	nt        dt        |      z        ||d<   t        |	      |d<   |rt        j                   |      }
t        j                  dkD  r8|
t         j"                     t        j                  kD  rt        j                  |d<   nt         j                  d |z         	 t%        |d!      5 }|j'                         }d d d        d%v rd|d&<   n;|r||d'<   n||d'<   t        |      |d(<   nt         j                  d)       d*|d'<   ||d(<   | j*                  j,                  rd|v rd|d<   d(|v rd+|d(<   |S # 1 sw Y   xxY w# t(        $ r }t        d"|d#t        |      d$      d }~ww xY w),Nz4Going to peek to see if file has changed permissionszansible.legacy.fileT)r   
_diff_peek)r   r   r\   r  rq  FzFailed to get diff between 'z' and 'z': rl   r   r   r   state)Nabsentbeforeappears_binaryr   
dst_binarysize
dst_largerzSlurping the file %szansible.legacy.slurp)r   contentr#   base64z.unknown encoding in content option, failed: %sbefore_header
src_largerz!Reading local copy of the file %srbz'Unexpected error while reading source (z) for diff: r      
src_binaryafter_headerafterzsource of file passed inzdynamically generatedzX [[ Diff output has been hidden because 'no_log: true' was specified for this result ]]
)r?   r  rv  r'   r   rJ   r<  r   basenamer   r   MAX_FILE_SIZE_FOR_DIFFr  	b64decoder   r   r   ST_SIZEopenreadr?  r3   r  )rA   destinationsourcer\   r  source_filer  peek_resultdest_resultdest_contentsstr   src_contentsrG  s                 r.   _get_diff_datazActionBase._get_diff_dataB  s    LM**-4[]a;bt + 5 ??8U+OOrwwO_O_`fOgitv}  J  N  N  OU  WZ  [  w\  ]  ^K??4#q(w'+;;!$X!12%&\"(Q-E-E-IkZ`Naded|d|N|%&%=%=\"5>?"22 6DkDZ't 3 = +$/	$:M":.);(.(8(8(G*+[^ghs^t+tuu,7D)%,]%;DNWWV_++a/Bt||4DqG_G_4_)*)A)AD&MM"E"NO@!&$/ 63+.88:L6
 ,.-.\*"3>D039D0(/(=W9:'?^$ &W::4!$X$ |W16 6$ @*ioqz{|q}+~@s0   7K KK KK 	L  K;;L c                p    | j                   j                         }| j                  j                  |||      S )z
            find a needle in haystack of paths, optionally using 'dirname' as a subdir.
            This will build the ordered list of paths to search and pass them to dwim
            to get back the first existing file found.
        )r3   get_search_pathr6   path_dwim_relative_stack)rA   r  needle
path_stacks       r.   _find_needlezActionBase._find_needle  s1     ZZ//1
 ||44Z&QQr/   )NN)NNNNNN)Fr  )NT)TN)rp  r   )NNNNFNFF)TNNsurrogate_then_replaceN)0__name__
__module____qualname____doc__rR   rQ   BYPASS_HOST_LOOPr   _requires_connectionrP   rM   rH   r   r`   rs   rw   r   r   r   r   r   r   r   rY   r   r   r	  r  r  rZ   r+  ru   r4  rH  r]  rO  rQ  rR  rP  ry  r  r  r  rv  r  r   r,  r2  r   r/   r.   r1   r1   4   s7    B-K OO & ) )V 482615/3+/+/02d
BXQXmH^GB7<>T"=~q6$$4Y8v(T4l>t@ UZ49S-1Sj.bNq`JXRr/   r1   )=
__future__r   r  r  r<  r  r  r  r   r:  abcr   r   collections.abcr   ansibler   r   ansible.errorsr   r	   r
   r   r   ansible.executor.module_commonr   &ansible.executor.interpreter_discoveryr   r   $ansible.module_utils.common.arg_specr   ansible.module_utils.errorsr   ansible.module_utils.json_utilsr   ansible.module_utils.sixr   r   r   +ansible.module_utils.common.text.convertersr   r   r   ansible.parsing.utils.jsonifyr   ansible.releaser   ansible.utils.collection_loaderr   ansible.utils.displayr   ansible.utils.unsafe_proxyr   r   ansible.vars.cleanr   ansible.utils.plugin_docsr    r?   r)   r1   r   r/   r.   <module>rM     s    #   	 	     # $ " F  F 8 j F 8 B I I T T 1 ' > ) B 3 ;
)	#eR eRr/   