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: //lib/python3.9/site-packages/ansible/modules/__pycache__/copy.cpython-39.pyc
a

�)g��@s$ddlmZmZmZeZdZdZdZddl	Z	ddl
Z
ddlZddlZddl
ZddlZddlZddlZddlZddlZddlZddlmZmZddlmZddlmZdd	lmZdd
lmZdaGdd�de �Z!d
d�Z"dd�Z#dd�Z$dd�Z%dd�Z&dd�Z'dd�Z(dd�Z)e*dk�r e)�dS)�)�absolute_import�division�print_functionaj
---
module: copy
version_added: historical
short_description: Copy files to remote locations
description:
    - The C(copy) module copies a file from the local or remote machine to a location on the remote machine.
    - Use the M(ansible.builtin.fetch) module to copy files from remote locations to the local box.
    - If you need variable interpolation in copied files, use the M(ansible.builtin.template) module.
      Using a variable in the C(content) field will result in unpredictable output.
    - For Windows targets, use the M(ansible.windows.win_copy) module instead.
options:
  src:
    description:
    - Local path to a file to copy to the remote server.
    - This can be absolute or relative.
    - If path is a directory, it is copied recursively. In this case, if path ends
      with "/", only inside contents of that directory are copied to destination.
      Otherwise, if it does not end with "/", the directory itself with all contents
      is copied. This behavior is similar to the C(rsync) command line tool.
    type: path
  content:
    description:
    - When used instead of C(src), sets the contents of a file directly to the specified value.
    - Works only when C(dest) is a file. Creates the file if it does not exist.
    - For advanced formatting or if C(content) contains a variable, use the
      M(ansible.builtin.template) module.
    type: str
    version_added: '1.1'
  dest:
    description:
    - Remote absolute path where the file should be copied to.
    - If C(src) is a directory, this must be a directory too.
    - If C(dest) is a non-existent path and if either C(dest) ends with "/" or C(src) is a directory, C(dest) is created.
    - If I(dest) is a relative path, the starting directory is determined by the remote host.
    - If C(src) and C(dest) are files, the parent directory of C(dest) is not created and the task fails if it does not already exist.
    type: path
    required: yes
  backup:
    description:
    - Create a backup file including the timestamp information so you can get the original file back if you somehow clobbered it incorrectly.
    type: bool
    default: no
    version_added: '0.7'
  force:
    description:
    - Influence whether the remote file must always be replaced.
    - If C(true), the remote file will be replaced when contents are different than the source.
    - If C(false), the file will only be transferred if the destination does not exist.
    type: bool
    default: yes
    version_added: '1.1'
  mode:
    description:
    - The permissions of the destination file or directory.
    - For those used to C(/usr/bin/chmod) remember that modes are actually octal numbers.
      You must either add a leading zero so that Ansible's YAML parser knows it is an octal number
      (like C(0644) or C(01777)) or quote it (like C('644') or C('1777')) so Ansible receives a string
      and can do its own conversion from string into number. Giving Ansible a number without following
      one of these rules will end up with a decimal number which will have unexpected results.
    - As of Ansible 1.8, the mode may be specified as a symbolic mode (for example, C(u+rwx) or C(u=rw,g=r,o=r)).
    - As of Ansible 2.3, the mode may also be the special string C(preserve).
    - C(preserve) means that the file will be given the same permissions as the source file.
    - When doing a recursive copy, see also C(directory_mode).
    - If C(mode) is not specified and the destination file B(does not) exist, the default C(umask) on the system will be used
      when setting the mode for the newly created file.
    - If C(mode) is not specified and the destination file B(does) exist, the mode of the existing file will be used.
    - Specifying C(mode) is the best way to ensure files are created with the correct permissions.
      See CVE-2020-1736 for further details.
  directory_mode:
    description:
    - When doing a recursive copy set the mode for the directories.
    - If this is not set we will use the system defaults.
    - The mode is only set on directories which are newly created, and will not affect those that already existed.
    type: raw
    version_added: '1.5'
  remote_src:
    description:
    - Influence whether C(src) needs to be transferred or already is present remotely.
    - If C(false), it will search for C(src) on the controller node.
    - If C(true) it will search for C(src) on the managed (remote) node.
    - C(remote_src) supports recursive copying as of version 2.8.
    - C(remote_src) only works with C(mode=preserve) as of version 2.6.
    - Autodecryption of files does not work when C(remote_src=yes).
    type: bool
    default: no
    version_added: '2.0'
  follow:
    description:
    - This flag indicates that filesystem links in the destination, if they exist, should be followed.
    type: bool
    default: no
    version_added: '1.8'
  local_follow:
    description:
    - This flag indicates that filesystem links in the source tree, if they exist, should be followed.
    type: bool
    default: yes
    version_added: '2.4'
  checksum:
    description:
    - SHA1 checksum of the file being transferred.
    - Used to validate that the copy of the file was successful.
    - If this is not provided, ansible will use the local calculated checksum of the src file.
    type: str
    version_added: '2.5'
extends_documentation_fragment:
    - decrypt
    - files
    - validate
    - action_common_attributes
    - action_common_attributes.files
    - action_common_attributes.flow
notes:
    - The M(ansible.builtin.copy) module recursively copy facility does not scale to lots (>hundreds) of files.
seealso:
    - module: ansible.builtin.assemble
    - module: ansible.builtin.fetch
    - module: ansible.builtin.file
    - module: ansible.builtin.template
    - module: ansible.posix.synchronize
    - module: ansible.windows.win_copy
author:
    - Ansible Core Team
    - Michael DeHaan
attributes:
  action:
    support: full
  async:
    support: none
  bypass_host_loop:
    support: none
  check_mode:
    support: full
  diff_mode:
    support: full
  platform:
    platforms: posix
  safe_file_operations:
      support: full
  vault:
    support: full
    version_added: '2.2'
a�
- name: Copy file with owner and permissions
  ansible.builtin.copy:
    src: /srv/myfiles/foo.conf
    dest: /etc/foo.conf
    owner: foo
    group: foo
    mode: '0644'

- name: Copy file with owner and permission, using symbolic representation
  ansible.builtin.copy:
    src: /srv/myfiles/foo.conf
    dest: /etc/foo.conf
    owner: foo
    group: foo
    mode: u=rw,g=r,o=r

- name: Another symbolic mode example, adding some permissions and removing others
  ansible.builtin.copy:
    src: /srv/myfiles/foo.conf
    dest: /etc/foo.conf
    owner: foo
    group: foo
    mode: u+rw,g-wx,o-rwx

- name: Copy a new "ntp.conf" file into place, backing up the original if it differs from the copied version
  ansible.builtin.copy:
    src: /mine/ntp.conf
    dest: /etc/ntp.conf
    owner: root
    group: root
    mode: '0644'
    backup: yes

- name: Copy a new "sudoers" file into place, after passing validation with visudo
  ansible.builtin.copy:
    src: /mine/sudoers
    dest: /etc/sudoers
    validate: /usr/sbin/visudo -csf %s

- name: Copy a "sudoers" file on the remote machine for editing
  ansible.builtin.copy:
    src: /etc/sudoers
    dest: /etc/sudoers.edit
    remote_src: yes
    validate: /usr/sbin/visudo -csf %s

- name: Copy using inline content
  ansible.builtin.copy:
    content: '# This file was moved to /etc/other.conf'
    dest: /etc/mine.conf

- name: If follow=yes, /path/to/file will be overwritten by contents of foo.conf
  ansible.builtin.copy:
    src: /etc/foo.conf
    dest: /path/to/link  # link to /path/to/file
    follow: yes

- name: If follow=no, /path/to/link will become a file and be overwritten by contents of foo.conf
  ansible.builtin.copy:
    src: /etc/foo.conf
    dest: /path/to/link  # link to /path/to/file
    follow: no
a;
dest:
    description: Destination file/path.
    returned: success
    type: str
    sample: /path/to/file.txt
src:
    description: Source file used for the copy on the target machine.
    returned: changed
    type: str
    sample: /home/httpd/.ansible/tmp/ansible-tmp-1423796390.97-147729857856000/source
md5sum:
    description: MD5 checksum of the file after running copy.
    returned: when supported
    type: str
    sample: 2a5aeecc61dc98c4d780b14b330e3282
checksum:
    description: SHA1 checksum of the file after running copy.
    returned: success
    type: str
    sample: 6e642bb8dd5c2e027bf21dd923337cbb4214f827
backup_file:
    description: Name of backup file created.
    returned: changed and if backup=yes
    type: str
    sample: /path/to/file.txt.2015-02-12@22:09~
gid:
    description: Group id of the file, after execution.
    returned: success
    type: int
    sample: 100
group:
    description: Group of the file, after execution.
    returned: success
    type: str
    sample: httpd
owner:
    description: Owner of the file, after execution.
    returned: success
    type: str
    sample: httpd
uid:
    description: Owner id of the file, after execution.
    returned: success
    type: int
    sample: 100
mode:
    description: Permissions of the target, after execution.
    returned: success
    type: str
    sample: "0644"
size:
    description: Size of the target, after execution.
    returned: success
    type: int
    sample: 1220
state:
    description: State of the target, after execution.
    returned: success
    type: str
    sample: file
N)�to_bytes�	to_native)�
AnsibleModule)�get_bin_path)�get_best_parsable_locale)�PY3c@seZdZdd�ZdS)�AnsibleModuleErrorcCs
||_dS)N��results)�selfr
�r�8/usr/lib/python3.9/site-packages/ansible/modules/copy.py�__init__4szAnsibleModuleError.__init__N)�__name__�
__module__�__qualname__rrrrrr3srcCsjtd�}|d|g}dd�|D�}tt�}tj|t|||d�d�\}}}|dkrftd�d	�|�||���dS)
N�setfaclz-bcSsg|]}t|��qSr)r)�.0�xrrr�
<listcomp>@�zclear_facls.<locals>.<listcomp>)�LANG�LC_ALL�LC_MESSAGES)Zenviron_updaterz1Error running "{0}": stdout: "{1}"; stderr: "{2}"� )rr	�module�run_command�dict�RuntimeError�format�join)�pathrZacl_commandZ
b_acl_command�locale�rc�out�errrrr�clear_facls<s
r)cCsztj�|�\}}t|dd�}|dkr.d|gfStj�|�s^|dkrPtddid��t|�\}}n
||gfS|�|�||fS)	zi
    Return the first pre-existing directory and a list of the new directories that will be created.
    �surrogate_or_strict��errors��.�/�msgz0The '/' directory doesn't exist on this machine.r)�osr$�splitr�existsr�split_pre_existing_dir�append)�dirname�head�tailZb_head�pre_existing_dir�new_directory_listrrrr4Gs


r4cCs@|r<tj�||�d��}||d<|�||�}t|||||�}|S)z]
    Walk the new directories list and make sure that permissions are as we would expect
    rr$)r1r$r#�pop�set_fs_attributes_if_different�&adjust_recursive_directory_permissions)r9r:r�directory_args�changedZworking_dirrrrr=Ysr=c
s�d}|jd}|jd}|du�rl|js�t�|�D]�\�}}|��|d�}|durV|}�fdd�|D�D]}|�||d�}|durh|}qh�fdd�|D�D]}	|�|	|d�}|dur�|}q�q2n�t�|�j}
t�|�D]�\�}}t���j	|
k}|dur�|}�fdd�|D�D]$}t�|�j	|
k}|du�r|}�q�fd	d�|D�D]$}	t�|	�j	|
k}|du�rD|}�qDq�|du�r�|j�s t�|�D]�\�}}|�
�|d�}|du�r�|}�fd
d�|D�D]"}|�
||d�}|du�r�|}�q��fdd�|D�D]"}	|�
|	|d�}|du�r�|}�q��q�n�t�|�j
}t�|�D]�\�}}t���j|k}|du�r^|}�fdd�|D�D]$}t�|�j|k}|du�rp|}�qp�fd
d�|D�D]$}	t�|	�j|k}|du�r�|}�q��q6|S)NF�owner�groupTcsg|]}tj��|��qSr�r1r$r#�r�d��dirpathrrrqrz#chown_recursive.<locals>.<listcomp>csg|]}tj��|��qSrrB�r�frErrrurcsg|]}tj��|��qSrrBrCrErrrrcsg|]}tj��|��qSrrBrGrErrr�rcsg|]}tj��|��qSrrBrCrErrr�rcsg|]}tj��|��qSrrBrGrErrr�rcsg|]}tj��|��qSrrBrCrErrr�rcsg|]}tj��|��qSrrBrGrErrr�r)�params�
check_moder1�walk�set_owner_if_different�pwd�getpwnam�pw_uid�stat�st_uid�set_group_if_different�grp�getgrnam�gr_gid�st_gid)
r$rr?r@rA�dirnames�	filenamesZ
owner_changed�dir�file�uidZ
group_changed�gidrrEr�chown_recursivefst













r]cCs�d}|jd}|jd}|jd}t�||�j}t|�r<d}|js�|D]�}tj�||�}	tj�||�}
t	|	dd�}t	|
dd�}tj�
|�r�|dur�t�|�}
t�|
|�nt
�||�t
�||�|dur�|�||d�|dur�|�||d�d}qF|S)	zKCopy files that are different between `src` directory and `dest` directory.Fr@rA�local_followTr*r+N)rI�filecmp�dircmp�
diff_files�lenrJr1r$r#r�islink�readlink�symlink�shutil�copyfile�copymoderLrR)�src�destrr?r@rAr^ra�item�
src_item_path�dest_item_path�b_src_item_path�b_dest_item_path�linktorrr�copy_diff_files�s0



rqcCs8d}|jd}|jd}|jd}t�||�j}t|�r<d}|j�s4|D�]�}tj�||�}	tj�||�}
t	|	dd�}t	|
dd�}tj�
|�r�tj�|�r�|dur�tj
|||d�t||�tj�
|�r�tj�|�r�|dur�t�|�}
t�|
|�tj�
|��rVtj�|��rV|du�rVt�||�|d	u�r>|�||d�|d	u�rV|�||d�tj�
|��r�tj�|��r�|du�r�t�|�}
t�|
|�tj�
|��s�tj�|��r�t�||�t�||�|d	u�r�|�||d�|d	u�r�|�||d�tj�
|��s.tj�|��r.tj
|||d�t||�d}qH|S)
zFCopy files that exist in `src` directory only to the `dest` directory.Fr@rAr^Tr*r+��symlinksN)rIr_r`�	left_onlyrbrJr1r$r#rrc�isdirrf�copytreer]rdre�isfilergrLrRrh)rirjrr?r@rAr^rtrkrlrmrnrorprrr�copy_left_only�sP



 
 
&

&



rxcCs�d}t�||�j}|D]�}tj�||�}tj�||�}t|dd�}t|dd�}	t||	|�}
t||	|�}|
sn|rrd}|p�t	tj�||�tj�||�|�}q|S)NFr*r+T)
r_r`�common_dirsr1r$r#rrqrx�copy_common_dirs)rirjrr?ryrkrlrmrnro�diff_files_changed�left_only_changedrrrrz�s&rzc)Cs�tttdd�tdd�tddd�tddd�tddd	�tddd	�tdd�td
d�tdd�tdd�tdd�tddd	�d�ddd�atjd
}t|dd�}tjd}tjj|vr�d�tjj|�}t|dd�}tjd}tjd}tj�	dd�}tj�	dd�}tjd}tjd}	tjd}
tjd}tjd}tjd}
tjd}tj�
|��sXtjd|d�t�|tj
��sxtjd|d�tjdd k�r�d!t�t�|�j�tjd<tjd}
d}d}d}d}tj�|��r>zt�|�}Wn<ttf�y}zt�d"t|��WYd}~n
d}~00zt�|�}Wnt�y:Yn0n&|
�rdtj�|��sdt�d#t|��|�r�||k�r�tjd$||d%�|�tj��r�|�r�tj�||�}t|dd�}tj�|�}t|dd�}tj�
|��s�zt|�\}}WnPt�y8}z6|jd&d'�|�7<tjfi|j ��WYd}~n
d}~00tj!�rVtj"d(|d|d)�t�#|�t�$tj�}tjd*}|du�r�||d<nd|d<t%||t||�tj�|��r�tj�&|�}|�r�|}tj�||�}t|dd�}tj�
|��r\tj�'|��r|�rtj�(|�}t|dd�}|�s2tj"d+||dd,�t�|tj
��r�tj�|��r�t�|�}n�tj�
tj�|���s�zt�tj�|��WnPt�y�}z6d-t|��)�v�r�tjd.tj�|�d�WYd}~n
d}~00tjd/tj�|�d�t�tj�|�tj*��s.tjd0�s.tjd1tj�|�d�d}||k�sJtj�'|��r tj!�s�z�|�rttj�
|��rtt�+|�}tj�'|��r�t�,|�t-|d2��.�|�r2|
du�r�t�/||
d�|du�r�t�0||d�|du�r�t�1||d�d3|v�rtjd4|d�t�2||�\}}}|d5k�r2tjd6|||d7�|}|
�r�tj�|��r�t3j4tj�|�d8�\} }t5�6||�zt5�7||�WnVt�y�}z<|j8t8j9k�r�|
d k�r�t�d9�t|���n�WYd}~n
d}~00t:�r&t;td:��r&zd;t�<|�v}!Wn*t=�y$}zd}!WYd}~n
d}~00tj>||tjd0d<�t:�r�t;td:��r�t?�@�d=k�r�|
�s�|!�r�ztA|�Wnnt�y�}zd>t|�v�r�n�WYd}~n@d}~0tB�y�}zd?t|�v�r�n�WYd}~n
d}~00Wn2ttf�ytjd@||ftC�D�dA�Yn0d}nd}|du�r||du�r||
�r|tj�tjd
��r|ttjd
dd�}ttjddd�}|�tjj��r�tj�tjd��r�tE||t�}"tF||t�}#tG||t�}$tH|t�}%|"�s�|#�s�|$�s�|%�r�d}|�tjj��	rvtj�
tjd��	svttj�&|�dd�}&ttj�||&�dd�}ttj�tjd
dB�dd�}tj!�	sht5jI|||	dC�tH|t�d}|�tjj��
s�tj�tjd��
r�ttj�&|�dd�}&ttj�||&�dd�}ttj�tjd
dB�dd�}tj!�
stj�
|��
st5jI|||	dC�d}tH|t�tj!�
r0tj�
|��
s0d}tj�
|��
r�tE||t�}"tF||t�}#tG||t�}$tH|t�}%|"�
s�|#�
s�|$�
s�|%�
r�d}|�tjj��s|tj�
tjd��s|ttj�&tjd
�dd�}&ttj�||&�dd�}tj!�sbtj�
|��sbt�#|�ttj�tjd
dB�dd�}tE||t�}"tF||t�}#tG||t�}$tH|t�}%|"�s^|#�s^|$�s^|%�rbd}tj!�r|tj�
|��s|d}t|||||dD�}'|�r�||'dE<tj$tj|dF�}(t�J|(|'dG�|'dG<tj"fi|'��dS)HNr$)�type�strT)r}Zno_log)r}�required�boolF)r}�default�raw)ri�_original_basenameZcontentrj�backup�force�validate�directory_mode�
remote_srcr^�checksum�follow)Z
argument_specZadd_file_common_argsZsupports_check_moderir*r+rjz.{0}{1}r�r�r�r�r�r^�moder@rAr�r�zSource %s not found)r0zSource %s not readableZpreservez0%03oz5Unable to calculate src checksum, assuming change: %sz+Cannot copy invalid source '%s': not a filezBCopied file does not match the expected checksum. Transfer failed.)r0r�Zexpected_checksumr0z Could not copy to {0}z"dest directory %s would be created)r0r?rir�zfile already exists)r0rirjr?zpermission deniedz*Destination directory %s is not accessiblez'Destination directory %s does not exist�
unsafe_writeszDestination %s not writable�wz%szvalidate must contain %%s: %srzfailed to validate)r0�exit_status�stdout�stderr)rYzUnable to copy stats {0}�	listxattrzsystem.posix_acl_access)r�ZLinuxrzOperation not supportedzfailed to copy: %s to %s)r0�	tracebackr-rr)rjriZmd5sumr�r?�backup_file)r$r?)Krr rrIrr1r$�sepr"�getr3Z	fail_json�access�R_OKrP�S_IMODE�st_moderwZsha1�OSError�IOError�warnrZmd5�
ValueErrorru�endswithr#r6r4r�resultr
rJZ	exit_json�makedirsZload_file_common_argumentsr=�basenamerc�realpath�lower�W_OKZbackup_local�unlink�open�closeZset_mode_if_differentrLrRr�tempfileZmkstemprfrg�copystat�errnoZENOSYSr
�hasattrr��	ExceptionZatomic_move�platform�systemr)r!r��
format_excrqrxrzr]rvr<))riZb_srcrjZb_destr�r�r�r�r�r^r�r@rAr�r�r?Z
checksum_destZchecksum_srcZ
md5sum_src�er6Z	b_dirnamer9r:r>r�r�r�r&r'r(Zb_mysrc�_Zsrc_has_aclsr{r|Zcommon_dirs_changedZowner_group_changedZ
b_basenameZres_argsZ	file_argsrrr�main
s�




��











(�(



.$






& $
$
$

$


�r��__main__)+Z
__future__rrrr}Z
__metaclass__Z
DOCUMENTATIONZEXAMPLESZRETURNr�r_rSr1Zos.pathr�rMrfrPr�r�Zansible.module_utils._textrrZansible.module_utils.basicrZ#ansible.module_utils.common.processrZ"ansible.module_utils.common.localer	Zansible.module_utils.sixr
rr�rr)r4r=r]rqrxrzr�rrrrr�<module>sFA?	
A5.