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

�)gwN�@s�ddlmZmZmZeZdZdZdZddl	Z	ddl
Z
ddlZddlZddl
Z
ddlmZddlmZdd	�Zd
d�Zedkr�e�dS)
�)�absolute_import�division�print_functiona
---
module: stat
version_added: "1.3"
short_description: Retrieve file or file system status
description:
     - Retrieves facts for a file similar to the Linux/Unix 'stat' command.
     - For Windows targets, use the M(ansible.windows.win_stat) module instead.
options:
  path:
    description:
      - The full path of the file/object to get the facts of.
    type: path
    required: true
    aliases: [ dest, name ]
  follow:
    description:
      - Whether to follow symlinks.
    type: bool
    default: no
  get_checksum:
    description:
      - Whether to return a checksum of the file.
    type: bool
    default: yes
    version_added: "1.8"
  checksum_algorithm:
    description:
      - Algorithm to determine checksum of file.
      - Will throw an error if the host is unable to use specified algorithm.
      - The remote host has to support the hashing method specified, C(md5)
        can be unavailable if the host is FIPS-140 compliant.
    type: str
    choices: [ md5, sha1, sha224, sha256, sha384, sha512 ]
    default: sha1
    aliases: [ checksum, checksum_algo ]
    version_added: "2.0"
  get_mime:
    description:
      - Use file magic and return data about the nature of the file. this uses
        the 'file' utility found on most Linux/Unix systems.
      - This will add both C(mimetype) and C(charset) fields to the return, if possible.
      - In Ansible 2.3 this option changed from I(mime) to I(get_mime) and the default changed to C(true).
    type: bool
    default: yes
    aliases: [ mime, mime_type, mime-type ]
    version_added: "2.1"
  get_attributes:
    description:
      - Get file attributes using lsattr tool if present.
    type: bool
    default: yes
    aliases: [ attr, attributes ]
    version_added: "2.3"
extends_documentation_fragment:
  -  action_common_attributes
attributes:
    check_mode:
        support: full
    diff_mode:
        support: none
    platform:
        platforms: posix
seealso:
- module: ansible.builtin.file
- module: ansible.windows.win_stat
author: Bruce Pennypacker (@bpennypacker)
a�
# Obtain the stats of /etc/foo.conf, and check that the file still belongs
# to 'root'. Fail otherwise.
- name: Get stats of a file
  ansible.builtin.stat:
    path: /etc/foo.conf
  register: st
- name: Fail if the file does not belong to 'root'
  ansible.builtin.fail:
    msg: "Whoops! file ownership has changed"
  when: st.stat.pw_name != 'root'

# Determine if a path exists and is a symlink. Note that if the path does
# not exist, and we test sym.stat.islnk, it will fail with an error. So
# therefore, we must test whether it is defined.
# Run this to understand the structure, the skipped ones do not pass the
# check performed by 'when'
- name: Get stats of the FS object
  ansible.builtin.stat:
    path: /path/to/something
  register: sym

- name: Print a debug message
  ansible.builtin.debug:
    msg: "islnk isn't defined (path doesn't exist)"
  when: sym.stat.islnk is not defined

- name: Print a debug message
  ansible.builtin.debug:
    msg: "islnk is defined (path must exist)"
  when: sym.stat.islnk is defined

- name: Print a debug message
  ansible.builtin.debug:
    msg: "Path exists and is a symlink"
  when: sym.stat.islnk is defined and sym.stat.islnk

- name: Print a debug message
  ansible.builtin.debug:
    msg: "Path exists and isn't a symlink"
  when: sym.stat.islnk is defined and sym.stat.islnk == False


# Determine if a path exists and is a directory.  Note that we need to test
# both that p.stat.isdir actually exists, and also that it's set to true.
- name: Get stats of the FS object
  ansible.builtin.stat:
    path: /path/to/something
  register: p
- name: Print a debug message
  ansible.builtin.debug:
    msg: "Path exists and is a directory"
  when: p.stat.isdir is defined and p.stat.isdir

- name: Do not calculate the checksum
  ansible.builtin.stat:
    path: /path/to/myhugefile
    get_checksum: no

- name: Use sha256 to calculate the checksum
  ansible.builtin.stat:
    path: /path/to/something
    checksum_algorithm: sha256
a�&
stat:
    description: Dictionary containing all the stat data, some platforms might add additional fields.
    returned: success
    type: complex
    contains:
        exists:
            description: If the destination path actually exists or not
            returned: success
            type: bool
            sample: True
        path:
            description: The full path of the file/object to get the facts of
            returned: success and if path exists
            type: str
            sample: '/path/to/file'
        mode:
            description: Unix permissions of the file in octal representation as a string
            returned: success, path exists and user can read stats
            type: str
            sample: 1755
        isdir:
            description: Tells you if the path is a directory
            returned: success, path exists and user can read stats
            type: bool
            sample: False
        ischr:
            description: Tells you if the path is a character device
            returned: success, path exists and user can read stats
            type: bool
            sample: False
        isblk:
            description: Tells you if the path is a block device
            returned: success, path exists and user can read stats
            type: bool
            sample: False
        isreg:
            description: Tells you if the path is a regular file
            returned: success, path exists and user can read stats
            type: bool
            sample: True
        isfifo:
            description: Tells you if the path is a named pipe
            returned: success, path exists and user can read stats
            type: bool
            sample: False
        islnk:
            description: Tells you if the path is a symbolic link
            returned: success, path exists and user can read stats
            type: bool
            sample: False
        issock:
            description: Tells you if the path is a unix domain socket
            returned: success, path exists and user can read stats
            type: bool
            sample: False
        uid:
            description: Numeric id representing the file owner
            returned: success, path exists and user can read stats
            type: int
            sample: 1003
        gid:
            description: Numeric id representing the group of the owner
            returned: success, path exists and user can read stats
            type: int
            sample: 1003
        size:
            description: Size in bytes for a plain file, amount of data for some special files
            returned: success, path exists and user can read stats
            type: int
            sample: 203
        inode:
            description: Inode number of the path
            returned: success, path exists and user can read stats
            type: int
            sample: 12758
        dev:
            description: Device the inode resides on
            returned: success, path exists and user can read stats
            type: int
            sample: 33
        nlink:
            description: Number of links to the inode (hard links)
            returned: success, path exists and user can read stats
            type: int
            sample: 1
        atime:
            description: Time of last access
            returned: success, path exists and user can read stats
            type: float
            sample: 1424348972.575
        mtime:
            description: Time of last modification
            returned: success, path exists and user can read stats
            type: float
            sample: 1424348972.575
        ctime:
            description: Time of last metadata update or creation (depends on OS)
            returned: success, path exists and user can read stats
            type: float
            sample: 1424348972.575
        wusr:
            description: Tells you if the owner has write permission
            returned: success, path exists and user can read stats
            type: bool
            sample: True
        rusr:
            description: Tells you if the owner has read permission
            returned: success, path exists and user can read stats
            type: bool
            sample: True
        xusr:
            description: Tells you if the owner has execute permission
            returned: success, path exists and user can read stats
            type: bool
            sample: True
        wgrp:
            description: Tells you if the owner's group has write permission
            returned: success, path exists and user can read stats
            type: bool
            sample: False
        rgrp:
            description: Tells you if the owner's group has read permission
            returned: success, path exists and user can read stats
            type: bool
            sample: True
        xgrp:
            description: Tells you if the owner's group has execute permission
            returned: success, path exists and user can read stats
            type: bool
            sample: True
        woth:
            description: Tells you if others have write permission
            returned: success, path exists and user can read stats
            type: bool
            sample: False
        roth:
            description: Tells you if others have read permission
            returned: success, path exists and user can read stats
            type: bool
            sample: True
        xoth:
            description: Tells you if others have execute permission
            returned: success, path exists and user can read stats
            type: bool
            sample: True
        isuid:
            description: Tells you if the invoking user's id matches the owner's id
            returned: success, path exists and user can read stats
            type: bool
            sample: False
        isgid:
            description: Tells you if the invoking user's group id matches the owner's group id
            returned: success, path exists and user can read stats
            type: bool
            sample: False
        lnk_source:
            description: Target of the symlink normalized for the remote filesystem
            returned: success, path exists and user can read stats and the path is a symbolic link
            type: str
            sample: /home/foobar/21102015-1445431274-908472971
        lnk_target:
            description: Target of the symlink.  Note that relative paths remain relative
            returned: success, path exists and user can read stats and the path is a symbolic link
            type: str
            sample: ../foobar/21102015-1445431274-908472971
            version_added: 2.4
        md5:
            description: md5 hash of the file; this will be removed in Ansible 2.9 in
                favor of the checksum return value
            returned: success, path exists and user can read stats and path
                supports hashing and md5 is supported
            type: str
            sample: f88fa92d8cf2eeecf4c0a50ccc96d0c0
        checksum:
            description: hash of the file
            returned: success, path exists, user can read stats, path supports
                hashing and supplied checksum algorithm is available
            type: str
            sample: 50ba294cdf28c0d5bcde25708df53346825a429f
        pw_name:
            description: User name of owner
            returned: success, path exists, user can read stats, owner name can be looked up and installed python supports it
            type: str
            sample: httpd
        gr_name:
            description: Group name of owner
            returned: success, path exists, user can read stats, owner group can be looked up and installed python supports it
            type: str
            sample: www-data
        mimetype:
            description: file magic data or mime-type
            returned: success, path exists and user can read stats and
                installed python supports it and the I(get_mime) option was true, will
                return C(unknown) on error.
            type: str
            sample: application/pdf; charset=binary
        charset:
            description: file character set or encoding
            returned: success, path exists and user can read stats and
                installed python supports it and the I(get_mime) option was true, will
                return C(unknown) on error.
            type: str
            sample: us-ascii
        readable:
            description: Tells you if the invoking user has the right to read the path
            returned: success, path exists and user can read the path
            type: bool
            sample: False
            version_added: 2.2
        writeable:
            description: Tells you if the invoking user has the right to write the path
            returned: success, path exists and user can write the path
            type: bool
            sample: False
            version_added: 2.2
        executable:
            description: Tells you if the invoking user has execute permission on the path
            returned: success, path exists and user can execute the path
            type: bool
            sample: False
            version_added: 2.2
        attributes:
            description: list of file attributes
            returned: success, path exists and user can execute the path
            type: list
            sample: [ immutable, extent ]
            version_added: 2.3
        version:
            description: The version/generation attribute of a file according to the filesystem
            returned: success, path exists, user can execute the path, lsattr is available and filesystem supports
            type: str
            sample: "381700746"
            version_added: 2.3
N)�
AnsibleModule)�to_bytesc!Cs4|j}td|dt�|�t�|�t�|�t�|�t�|�t�|�t�	|�t�
|�|j|j|j
|j|j|j|j|j|jt|tj@�t|tj@�t|tj@�t|tj@�t|tj@�t|tj@�t|tj@�t|tj@�t|tj@�t|tj@�t|tj@�d�}dD],}t ||d��rt!||d�||d<�q|S)NTz%04o)�exists�path�mode�isdirZischrZisblk�isregZisfifo�islnkZissock�uid�gid�size�inode�devZnlinkZatime�mtime�ctimeZwusrZrusrZxusrZwgrpZrgrpZxgrpZwothZrothZxothZisuidZisgid))�	st_blocksZblocks)�
st_blksizeZ
block_size)�st_rdevZdevice_type)�st_flags�flags)Zst_genZ
generation)Zst_birthtimeZ	birthtime)Zst_ftype�	file_type)Zst_attrs�attrs)Z	st_obtypeZobject_type)Zst_rsizeZ	real_size)Z
st_creatorZcreator)Zst_typerr�)"�st_mode�dict�stat�S_IMODE�S_ISDIR�S_ISCHR�S_ISBLK�S_ISREG�S_ISFIFO�S_ISLNK�S_ISSOCK�st_uid�st_gid�st_size�st_ino�st_dev�st_nlink�st_atime�st_mtime�st_ctime�bool�S_IWUSR�S_IRUSR�S_IXUSR�S_IWGRP�S_IRGRP�S_IXGRP�S_IWOTH�S_IROTH�S_IXOTH�S_ISUID�S_ISGID�hasattr�getattr)�moduler�str	�output�other�rB�8/usr/lib/python3.9/site-packages/ansible/modules/stat.py�
format_output�sJ�"rDcCs�tttddddgd�tddd�tddd�tddd�tddgd	�d
�tddddgd
�td
dgd�ddgd�d�dd�}|j�d�}t|dd�}|j�d�}|j�d�}|j�d�}|j�d�}|j�d�}|j�d�}z|r�t�|�}	n
t�|�}	WnXt�yJ}
z>|
j	t	j
k�r(ddi}|jd|d�|j|
j
d�WYd}
~
n
d}
~
00t|||	�}d tjfd!tjfd"tjffD]}t�||d#�||d$<�qt|�d%��r�tj�|�|d&<t�|�|d'<zt�|	j�}
|
j|d(<Wnttf�y�Yn0zt�|	j�}|j|d)<Wntt t!f�y&Yn0|�d*��r�|�d ��r�|�rvz|�"|�|d+<Wnt �ytd|d+<Yn0|�r�|�#||�|d<|�r.d,|d-<|d.<|�$d/�}|�r.|d0d1|g}zZ|�%|�\}}}|d$k�r|�&d2d#�d#�'d3�\}}|�(�|d-<|�'d4�d#�(�|d.<Wnt)�y,Yn0|�rxd|d5<g|d<d6|d7<|�*|�}d8D]}||v�rZ||||<�qZ|jd|d�dS)9NrT�dest�name)�type�required�aliasesr0F)rG�default)ZmimeZ	mime_typez	mime-type)rGrJrI�attr�
attributes�str�sha1)�md5rNZsha224Zsha256Zsha384Zsha512ZchecksumZ
checksum_algo)rGrJ�choicesrI)r�follow�get_md5�get_checksum�get_mime�get_attributes�checksum_algorithm)Z
argument_specZsupports_check_modeZsurrogate_or_strict)�errorsrQrTrUrSrVrRr)Zchangedr)�msg�readableZ	writeable�
executablerrrZ
lnk_sourceZ
lnk_target�pw_name�gr_namerrO�unknown�mimetype�charset�filez--mime-typez--mime-encoding�:�;�=�version��
attr_flags)rdrLrf)+rr�params�getr�osr�lstat�OSError�errno�ENOENTZ	exit_jsonZ	fail_json�strerrorrD�R_OK�W_OK�X_OK�accessr�realpath�readlink�pwd�getpwuidr'r[�	TypeError�KeyError�grp�getgrgidr(r\�
ValueError�
OverflowErrorrOZdigest_from_fileZget_bin_pathZrun_command�rsplit�split�strip�	ExceptionZget_file_attributes)r>r�b_pathrQrTZget_attrrSrVrRr?�er@ZpermZpwZgrp_infoZmimecmd�rc�out�errr^r_�xrBrBrC�main�s�


���$ 



r��__main__)Z
__future__rrrrGZ
__metaclass__Z
DOCUMENTATIONZEXAMPLESZRETURNrlryrirurZansible.module_utils.basicrZansible.module_utils._textrrDr��__name__rBrBrBrC�<module>s EAm>k