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__/file.cpython-39.pyc
a

�)g���@sbddlmZmZmZeZdZdZdZddl	Z	ddl
Z
ddlZddlZddl
Z
ddlmZmZddlmZmZddlmZdd	lmZmZdaGd
d�de�ZGdd
�d
e�ZGdd�de�Zdd�Zdd�Z dd�Z!dd�Z"dd�Z#dd�Z$d5dd�Z%dd�Z&d d!�Z'd"d#�Z(d$d%�Z)d&d'�Z*d(d)�Z+d*d+�Z,d,d-�Z-d.d/�Z.d0d1�Z/d2d3�Z0e1d4k�r^e0�dS)6�)�absolute_import�division�print_functionaZ
---
module: file
version_added: historical
short_description: Manage files and file properties
extends_documentation_fragment: [files, action_common_attributes]
description:
- Set attributes of files, directories, or symlinks and their targets.
- Alternatively, remove files, symlinks or directories.
- Many other modules support the same options as the C(file) module - including M(ansible.builtin.copy),
  M(ansible.builtin.template), and M(ansible.builtin.assemble).
- For Windows targets, use the M(ansible.windows.win_file) module instead.
options:
  path:
    description:
    - Path to the file being managed.
    type: path
    required: yes
    aliases: [ dest, name ]
  state:
    description:
    - If C(absent), directories will be recursively deleted, and files or symlinks will
      be unlinked. In the case of a directory, if C(diff) is declared, you will see the files and folders deleted listed
      under C(path_contents). Note that C(absent) will not cause C(file) to fail if the C(path) does
      not exist as the state did not change.
    - If C(directory), all intermediate subdirectories will be created if they
      do not exist. Since Ansible 1.7 they will be created with the supplied permissions.
    - If C(file), with no other options, returns the current state of C(path).
    - If C(file), even with other options (such as C(mode)), the file will be modified if it exists but will NOT be created if it does not exist.
      Set to C(touch) or use the M(ansible.builtin.copy) or M(ansible.builtin.template) module if you want to create the file if it does not exist.
    - If C(hard), the hard link will be created or changed.
    - If C(link), the symbolic link will be created or changed.
    - If C(touch) (new in 1.4), an empty file will be created if the file does not
      exist, while an existing file or directory will receive updated file access and
      modification times (similar to the way C(touch) works from the command line).
    - Default is the current state of the file if it exists, C(directory) if C(recurse=yes), or C(file) otherwise.
    type: str
    choices: [ absent, directory, file, hard, link, touch ]
  src:
    description:
    - Path of the file to link to.
    - This applies only to C(state=link) and C(state=hard).
    - For C(state=link), this will also accept a non-existing path.
    - Relative paths are relative to the file being created (C(path)) which is how
      the Unix command C(ln -s SRC DEST) treats relative paths.
    type: path
  recurse:
    description:
    - Recursively set the specified file attributes on directory contents.
    - This applies only when C(state) is set to C(directory).
    type: bool
    default: no
    version_added: '1.1'
  force:
    description:
    - >
      Force the creation of the symlinks in two cases: the source file does
      not exist (but will appear later); the destination exists and is a file (so, we need to unlink the
      C(path) file and create symlink to the C(src) file in place of it).
    type: bool
    default: no
  follow:
    description:
    - This flag indicates that filesystem links, if they exist, should be followed.
    - I(follow=yes) and I(state=link) can modify I(src) when combined with parameters such as I(mode).
    - Previous to Ansible 2.5, this was C(false) by default.
    type: bool
    default: yes
    version_added: '1.8'
  modification_time:
    description:
    - This parameter indicates the time the file's modification time should be set to.
    - Should be C(preserve) when no modification is required, C(YYYYMMDDHHMM.SS) when using default time format, or C(now).
    - Default is None meaning that C(preserve) is the default for C(state=[file,directory,link,hard]) and C(now) is default for C(state=touch).
    type: str
    version_added: "2.7"
  modification_time_format:
    description:
    - When used with C(modification_time), indicates the time format that must be used.
    - Based on default Python format (see time.strftime doc).
    type: str
    default: "%Y%m%d%H%M.%S"
    version_added: '2.7'
  access_time:
    description:
    - This parameter indicates the time the file's access time should be set to.
    - Should be C(preserve) when no modification is required, C(YYYYMMDDHHMM.SS) when using default time format, or C(now).
    - Default is C(None) meaning that C(preserve) is the default for C(state=[file,directory,link,hard]) and C(now) is default for C(state=touch).
    type: str
    version_added: '2.7'
  access_time_format:
    description:
    - When used with C(access_time), indicates the time format that must be used.
    - Based on default Python format (see time.strftime doc).
    type: str
    default: "%Y%m%d%H%M.%S"
    version_added: '2.7'
seealso:
- module: ansible.builtin.assemble
- module: ansible.builtin.copy
- module: ansible.builtin.stat
- module: ansible.builtin.template
- module: ansible.windows.win_file
attributes:
    check_mode:
        support: full
    diff_mode:
        details: permissions and ownership will be shown but file contents on absent/touch will not.
        support: partial
    platform:
        platforms: posix
author:
- Ansible Core Team
- Michael DeHaan
a$
- name: Change file ownership, group and permissions
  ansible.builtin.file:
    path: /etc/foo.conf
    owner: foo
    group: foo
    mode: '0644'

- name: Give insecure permissions to an existing file
  ansible.builtin.file:
    path: /work
    owner: root
    group: root
    mode: '1777'

- name: Create a symbolic link
  ansible.builtin.file:
    src: /file/to/link/to
    dest: /path/to/symlink
    owner: foo
    group: foo
    state: link

- name: Create two hard links
  ansible.builtin.file:
    src: '/tmp/{{ item.src }}'
    dest: '{{ item.dest }}'
    state: hard
  loop:
    - { src: x, dest: y }
    - { src: z, dest: k }

- name: Touch a file, using symbolic modes to set the permissions (equivalent to 0644)
  ansible.builtin.file:
    path: /etc/foo.conf
    state: touch
    mode: u=rw,g=r,o=r

- name: Touch the same file, but add/remove some permissions
  ansible.builtin.file:
    path: /etc/foo.conf
    state: touch
    mode: u+rw,g-wx,o-rwx

- name: Touch again the same file, but do not change times this makes the task idempotent
  ansible.builtin.file:
    path: /etc/foo.conf
    state: touch
    mode: u+rw,g-wx,o-rwx
    modification_time: preserve
    access_time: preserve

- name: Create a directory if it does not exist
  ansible.builtin.file:
    path: /etc/some_directory
    state: directory
    mode: '0755'

- name: Update modification and access time of given file
  ansible.builtin.file:
    path: /etc/some_file
    state: file
    modification_time: now
    access_time: now

- name: Set access time based on seconds from epoch value
  ansible.builtin.file:
    path: /etc/another_file
    state: file
    access_time: '{{ "%Y%m%d%H%M.%S" | strftime(stat_var.stat.atime) }}'

- name: Recursively change ownership of a directory
  ansible.builtin.file:
    path: /etc/foo
    state: directory
    recurse: yes
    owner: foo
    group: foo

- name: Remove file (delete file)
  ansible.builtin.file:
    path: /etc/foo.txt
    state: absent

- name: Recursively remove directory
  ansible.builtin.file:
    path: /etc/foo
    state: absent

ak
dest:
    description: Destination file/path, equal to the value passed to I(path).
    returned: state=touch, state=hard, state=link
    type: str
    sample: /path/to/file.txt
path:
    description: Destination file/path, equal to the value passed to I(path).
    returned: state=absent, state=directory, state=file
    type: str
    sample: /path/to/file.txt
N)�getpwnam�getpwuid)�getgrnam�getgrgid)�
AnsibleModule)�to_bytes�	to_nativec@seZdZdd�Zdd�ZdS)�AnsibleModuleErrorcCs
||_dS�N��results)�selfr�r�8/usr/lib/python3.9/site-packages/ansible/modules/file.py�__init__�szAnsibleModuleError.__init__cCsd�|j�S)NzAnsibleModuleError(results={0}))�formatr)rrrr�__repr__�szAnsibleModuleError.__repr__N)�__name__�
__module__�__qualname__rrrrrrr�src@seZdZdS)�ParameterErrorN)rrrrrrrr�src@seZdZdd�ZdS)�SentinelcOs|Sr
r)�cls�args�kwargsrrr�__new__szSentinel.__new__N)rrrrrrrrrsrcCs0t|t�rtjfi|j��nt�|||�dSr
)�
issubclassr�moduleZ	fail_jsonr�sys�__excepthook__)�exc_type�	exc_value�tbrrr�_ansible_excepthooks
r&cCs|ddvrltj�t|ddd��rld}|dr:|d}n|drRtj�|d�}|rltj�|d|�|d<tt|ddd��}|ddur�|d	kr�||d<n|d
r�d|d<nd|d<|d
r�|ddkr�td
|dd�d��|d�r|ddv�rtd|dd�d��dS)z0Additional parameter validation and reformatting�state)�link�absent�path�surrogate_or_strict��errorsN�_original_basename�srcr)�recurse�	directory�filez/recurse option requires state to be 'directory'��msgr*r)r(�hardz0src option requires state to be 'link' or 'hard')�osr*�isdirr
�basename�join�	get_stater)�paramsr8�
prev_staterrr�additional_parameter_handlings.$


�
�r=c
Cs�t|dd�}zRtj�|�rZtj�|�r,WdStj�|�r>WdSt�|�jdkrTWdSWdSWdSty�}z(|j	t	j
kr�WYd	}~dS�WYd	}~n
d	}~00d	S)
z Find out current state r+r,r(r1�r5r2r)N)r
r6r*�lexists�islinkr7�stat�st_nlink�OSError�errno�ENOENT)r*�b_path�errrr:>sr:c

Cs�d}�zNt�|�D�]<\}}}||D�]&}	tj�||	�}
tj�|
�s�|��}t|
dd�|d<|tj||dd�O}|t	|d||�O}q&|��}t|
dd�|d<|tj||dd�O}|t	|d||�O}|r&tj�|t�
|
��}
tj�|
�r&tj�|
��r|t
|
||||�O}|��}t|
dd�|d<|tj||dd�O}|t	|d||�O}q&qWnDt�y�}z*tddt|�t|�fid��WYd}~n
d}~00|S)	NFr+r,r*��expandr4zDCould not recursively set attributes on %s. Original error was: '%s'r)r6�walkr*r9r@�copyrr �set_fs_attributes_if_different�update_timestamp_for_file�readlink�existsr7�recursive_set_attributes�RuntimeErrorr)
rF�follow�	file_args�mtime�atime�changedZb_rootZb_dirsZb_filesZb_fsobjZb_fsname�
tmp_file_argsrGrrrrPWs8�rPc
Cs�d|id|id�}||kr�||dd<||dd<|dkr�|dkr�ggd�}t|d	d
�}t�|�D]V\}}}|D] }	tj�||	�}
|d�|
�qp|D] }tj�||�}|d�|�q�qb||dd
<|S)Nr*)�before�afterrXr'rYr)r1)�directories�filesr+r,rZr[Zpath_content)r
r6rJr*r9�append)
r*r'r<�diffZwalklistrF�	base_pathZsub_foldersr[ZfolderZ
folderpath�filename�filepathrrr�initial_diff�s(��racCs�|dkrdS|dkrtSzt�||�}t�|�}WnHttfyz}z,tdd||t|dd�fid��WYd}~n
d}~00|SdS)N�preserve�nowr4z?Error while obtaining timestamp for time %s using format %s: %s�
simplerepr�Z	nonstringr)r�time�strptime�mktime�
ValueError�
OverflowErrorrr)Zformatted_timeZtime_format�struct�struct_timerGrrr�get_timestamp_for_time�s� rmc	
Cs�t|dd�}�zH|turJ|turJt��}}t�|�j}t�|�j}d}n�|dur`|dur`WdSt�|�j}t�|�j}|dur�|}n|tur�t��}|dur�|}n|tur�t��}||kr�||kr�WdS||f}tjs�t�	||�|du�rTd|vr�i|d<d|v�ri|d<||k�r2||dd<||dd<||k�rT||dd<||dd<WnBt
�y�}z(tdt|d	d
�|d�d��WYd}~n
d}~00d
S)Nr+r,FrXrYrTrUz4Error while updating modification or access time: %srdrer3rT)
r
rrfr6rA�st_mtime�st_atimer �
check_mode�utimerCrr)	r*rTrUr]rFZprevious_mtimeZprevious_atimeZset_timerGrrrrM�sT




�� rMcCs0|dvr|durdS|dkr(|dur(dS|SdS)N)r2r5r1r(rb�touchrcr)Z	parameterr'rrr�)keep_backward_compatibility_on_timestamps�s
rscCslt|dd�}d}z8t|d��}|�d�}Wd�n1s<0YWntyZYn0d|vrhd}|S)	z2Take a guess as to whether a file is a binary filer+r,F�rbi N�T)r
�open�read�	Exception)r*rF�appears_binary�f�headrrr�execute_diff_peek�s,r|c
Cst|dd�}t|�}i}|dkr�t|d|�}tjs�|dkr�ztj|dd�Wq�ty�}z"tddt	|�id	��WYd}~q�d}~00nXzt
�|�WnHty�}z0|j
t
jkr�td
t	|�|d�d	��WYd}~n
d}~00|�|d|dd
��n|�|ddd��|S)Nr+r,r)r1F)�
ignore_errorsr4zrmtree failed: %srzunlinking failed: %s r3T)r*rVr]r')r*rVr')r
r:rar rp�shutil�rmtreerxrrr6�unlinkrCrDrE�update)r*rFr<�resultr]rGrrr�
ensure_absents*.� r�c
CsXt|dd�}t|�}d}d|i}t|d|d�}t|d|d�}|d	kr�tjr^d
|d<|Szt|d���d
}WnDttfy�}	z(t	d
t
|	dd�|d�d��WYd}	~	n
d}	~	00t|d|�}
t�tj
�}z,tj|||
dd�}|t|d|||
�O}WnDt�yB}	z*|	j�r,|d	k�r,t�|��WYd}	~	n
d}	~	00||d<|
|d<|S)Nr+r,F�dest�modification_time�modification_time_format�access_time�access_time_formatr)TrV�wbz!Error, could not touch target: %srdrer3rrrrHr*r])r
r:rmr rprv�closerC�IOErrorrrra�load_file_common_argumentsr;rLrM�
SystemExit�coder6�remove)r*rR�
timestampsrFr<rVr�rTrUrGr]rSrrr�
execute_touch$s@
�� 

r�c
Cs�t|dd�}t|�}t�tj�}t|d|d�}t|d|d�}|dkr�|r�|dkr�tj�|�}t	|d	d�}t|�}||d
<|dvr�t
d||f||d
�d��t|d|�}tj|d|dd�}	|	t
|d
|||�O}	||	|d�S)Nr+r,r�r�r�r�r2r(�strictr*�r2r5z file (%s) is %s, cannot continue)r4r*r'rFrH�r*rVr])r
r:r r�r;rmr6r*�realpathrrrarLrM)
r*rRr�rFr<rSrTrUr]rVrrr�ensure_file_attributesOs&�
r�cCsNt|dd�}t|�}t�tj�}t|d|d�}t|d|d�}|rx|dkrxtj�|�}t	|dd�}||d	<t|�}d
}	t
|d|�}
|dk�r�tjr�|d
|
d�Sd}z�|�d��
d�D]�}d�||g�}tj�|�s�|�d�}t|dd�}
tj�|
�s�zt�|
�d
}	WnDt�yP}z*|jtjk�r:tj�|
��s<�WYd}~n
d}~00|��}||d	<tj||	|
d
d�}	|	t|d	|||
�O}	q�WnBt�y�}z(td|t	|�f|d�d��WYd}~n
d}~00||	|
d�S|dk�rtd||f|d�d��tj||	|
d
d�}	|	t|d	|||
�O}	|�rB|	t|||||�O}	||	|
d�S)Nr+r,r�r�r�r�r(r�r*Fr1r)Tr���/rHz/There was an issue creating %s as requested: %sr3rz%s already exists as a %s)r
r:r r�r;rmr6r*r�rrarp�strip�splitr9�isabs�lstriprO�mkdirrCrDZEEXISTr7rKrLrMrxrrP)r*rRr0r�rFr<rSrTrUrVr]Zcurpath�dirnameZ	b_curpath�exrWrGrrr�ensure_directoryisb



�� 
�
r�c
Cs�t|dd�}t|dd�}t|�}t|d|d�}t|d|d�}	|durz|rztj�|�rztt�|�dd�}t|dd�}tj�|�s�tj�	|�r�|}
ntj�
|�}t|dd�}
|dur�d}ntj�|
|�}t|dd�}
|�s|du�rtj�|
��std|||d	�d
��|dk�rX|�s6td||f|d
�d
��n t�
|��r�td||d
�d
��n(|dv�r�|�s�td||f|d
�d
��t|d|�}d}|dv�r�|du�r�tddid
��d}n`|dk�r|du�rt�|�}||k�rt|dd�|dd<||dd<d}ntd||d�d
��|�rDtj�sD|dk�r�ttjj��tj�
|�tdt��t��f�g�}z0|dk�rxt�|�t�||�t�||�WnZt�y�}z@tj�|��r�t�|�tdt|dd�|d
�d
��WYd}~n
d}~00nTzt�||�WnBt�yB}z(td t|dd�|d
�d
��WYd}~n
d}~00tj�rhtj�|��sh||||d!�St�tj�}|�r�tj�|��r�tj�|d"��s�t�d#�n(tj|||dd$�}|t|d"||	|�O}||||d!�S)%Nr+r,r�r�r�r�r�zRsrc file does not exist, use "force=yes" if you really want to create the link: %s)r4r*r/rr1z-refusing to convert from %s to symlink for %sr3z5the directory %s is not empty, refusing to convert itr�r(F)r5r2r1r)r4z)src is required for creating new symlinksTrXr/rY�unexpected position reached�r4r�r/r)�
.%s.%s.tmp�Error while replacing: %srdre�Error while linking: %s�r�r/rVr]r*zgCannot set fs attributes on a non-existent symlink target. follow should be set to False to avoid this.rH)r
r:rmr6r*rOrrNr@r7r�r9r�listdirrar rp�sep�getpidrf�rmdir�symlink�renamerCr�r�r;�warnrLrM)r*r/rR�forcer�rF�b_srcr<rTrU�relpathZ	b_relpathZabsrcZb_absrcr]rV�	b_old_src�	b_tmppathrGrSrrr�ensure_symlink�s���

������







"�



��"
�� &r�c
Cs�t|dd�}t|dd�}t|�}t�tj�}t|d|d�}	t|d|d�}
|dkrn|durntdd	id
��|dur�tj�	|�s�td||d�d
��t
|d|�}d
}|dkr�d}�n$|dkr�t�|�}
|
|kr�t|
dd�|dd<||dd<d}n�|dk�r@|du�r�t�
|�jt�
|�jk�s�d}|�s�td||d�d
��n�|dk�rld}|�s�td|||d�d
��nl|dk�r�d}tj�	|��r�t�
|�jt�
|�jk�r�|d
d�S|�s�td||d�d
��ntd||d�d
��|�rNtj�sN|dk�r�ttjj��tj�|�tdt��t��f�g�}zz|dk�r�tj�	|��r�zt�|�Wn6t�y�}z|jtjk�rl�WYd}~n
d}~00t�||�t�||�WnZt�y�}z@tj�	|��r�t�|�tdt|dd�|d �d
��WYd}~n
d}~00nTzt�||�WnBt�yL}z(td!t|dd�|d �d
��WYd}~n
d}~00tj�rrtj�	|��sr||||d"�Stj|||d
d#�}|t|d$|	|
|�O}||||d"�S)%Nr+r,r�r�r�r�r5r4z*src is required for creating new hardlinksrzsrc does not existr�Fr)Tr(r�rXr/rYz6Cannot link, different hard link exists at destinationr2z%Cannot link, %s exists at destinationr1)r*rVz6Cannot link: different hard link exists at destinationr�r�r�rdrer3r�r�rHr*)r
r:r r�r;rmrr6r*rOrarNrrA�st_inorpr�r9r�r�rfr�rCrDrEr(r�rLrM)r*r/rRr�r�rFr�r<rSrTrUr]rVr�r�rGrrr�ensure_hardlinks�

$�
�

�
"�


��"
�� r�cCs�z<t|�}zt|�jWn ty8|�d|�Yn0WnBty~zt|�jWn tyx|�d|�Yn0Yn0dS)NzMfailed to look up user with uid %s. Create user up to this point in real playzDfailed to look up user %s. Create user up to this point in real play)�intr�pw_name�KeyErrorr�rir�pw_uid)r �owner�uidrrr�check_owner_existsysr�cCs�z<t|�}zt|�jWn ty8|�d|�Yn0WnBty~zt|�jWn tyx|�d|�Yn0Yn0dS)NzOfailed to look up group with gid %s. Create group up to this point in real playzFfailed to look up group %s. Create group up to this point in real play)r�r�gr_namer�r�rir�gr_gid)r �group�gidrrr�check_group_exists�sr�cCs4tttdgd�d�tddddgd�tdd	�td
dd�td
dd�td
dd�td
d	�tdd	�tdd	�tdd
d�tdd	�tdd
d�d�ddd�att_ttj�tj}|d}|d}|d}|d}|d}|d}tj�r|dk�rt�	tj�}|d�rt
t|d�|d�rtt|d�i}t|d|�|d<|d|d<t|d|�|d<|d|d<|ddu�r�t
t|dd��}	tj|d|	d�|d k�r�t|||�}
n||d!k�r�t||||�}
nb|d"k�r�t|||||�}
nF|d#k�r�t|||||�}
n*|d$k�rt|||�}
n|dk�r t|�}
tjfi|
��dS)%N�str)r)r1r2r5r(rr)�type�choicesr*Tr��name)r��required�aliases)r��boolF)r��defaultz
%Y%m%d%H%M.%S)r'r*r.r0r�rR�
_diff_peekr/r�r�r�r�)Z
argument_specZadd_file_common_argsZsupports_check_moder'r0r�rRr/r)r�r�r�r�r�r�r�r+r,)r*rVryr2r1r(r5rr)r	�dictr r&r!�
excepthookr=r;rpr�r�r�rsr|r
Z	exit_jsonr�r�r�r�r�r�)r;r'r0r�rRr*r/rSr�ryr�rrr�main�sl




��








r��__main__)N)2Z
__future__rrrr�Z
__metaclass__Z
DOCUMENTATIONZEXAMPLESZRETURNrDr6r~r!rf�pwdrr�grprrZansible.module_utils.basicr	Zansible.module_utils._textr
rr rxrr�objectrr&r=r:rPrarmrMrsr|r�r�r�r�r�r�r�r�r�rrrrr�<module>sJtZ
.+ 
;	+GoZE