Anons79 Mini Shell

Directory : /lib/python2.7/site-packages/ansible/modules/files/
Upload File :
Current File : //lib/python2.7/site-packages/ansible/modules/files/file.pyo

�
�Udac@`s�ddlmZmZmZeZidd6dgd6dd6ZdZd	Zd
Z	ddl
Z
ddlZddlZddl
Z
ddlZddlmZdd
lmZmZdadefd��YZdefd��YZdefd��YZd�Zd�Zd�Zd�Zd�Zd�Z dd�Z!d�Z"d�Z#d�Z$d�Z%d�Z&d �Z'd!�Z(d"�Z)d#�Z*e+d$kr�e*�ndS(%i(tabsolute_importtdivisiontprint_functions1.1tmetadata_versiontstableinterfacetstatustcoretsupported_bys�
---
module: file
version_added: historical
short_description: Manage files and file properties
extends_documentation_fragment: files
description:
- Set attributes of files, symlinks or directories.
- Alternatively, remove files, symlinks or directories.
- Many other modules support the same options as the C(file) module - including M(copy), M(template), and M(assemble).
- For Windows targets, use the M(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), without any other options this works mostly as a 'stat' and will return the current state of C(path).
      Even with other options (i.e C(mode)), the file will be modified but will NOT be created if it does not exist;
      see the C(touch) value or the M(copy) or M(template) module if you want that behavior.
    - 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 C(path) 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).
    type: str
    default: file
    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.
    - Previous to Ansible 2.5, this was C(no) 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: assemble
- module: copy
- module: stat
- module: template
- module: win_file
author:
- Ansible Core Team
- Michael DeHaan
sR
- name: Change file ownership, group and permissions
  file:
    path: /etc/foo.conf
    owner: foo
    group: foo
    mode: '0644'

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

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

- name: Create two hard links
  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)
  file:
    path: /etc/foo.conf
    state: touch
    mode: u=rw,g=r,o=r

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

- name: Touch again the same file, but dont change times this makes the task idempotent
  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
  file:
    path: /etc/some_directory
    state: directory
    mode: '0755'

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

- name: Set access time based on seconds from epoch value
  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
  file:
    path: /etc/foo
    state: directory
    recurse: yes
    owner: foo
    group: foo

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

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

s

N(t
AnsibleModule(tto_bytest	to_nativetAnsibleModuleErrorcB`seZd�Zd�ZRS(cC`s
||_dS(N(tresults(tselfR((s>/usr/lib/python2.7/site-packages/ansible/modules/files/file.pyt__init__�scC`stdj|j��dS(NsAnsibleModuleError(results={0})(tprinttformatR(R
((s>/usr/lib/python2.7/site-packages/ansible/modules/files/file.pyt__repr__�s(t__name__t
__module__RR(((s>/usr/lib/python2.7/site-packages/ansible/modules/files/file.pyR�s	tParameterErrorcB`seZRS((RR(((s>/usr/lib/python2.7/site-packages/ansible/modules/files/file.pyR�stSentinelcB`seZd�ZRS(cO`s|S(N((tclstargstkwargs((s>/usr/lib/python2.7/site-packages/ansible/modules/files/file.pyt__new__�s(RRR(((s>/usr/lib/python2.7/site-packages/ansible/modules/files/file.pyR�scC`s9t|t�r"tj|j�ntj|||�dS(N(t
issubclassRtmodulet	fail_jsonRtsyst__excepthook__(texc_typet	exc_valuettb((s>/usr/lib/python2.7/site-packages/ansible/modules/files/file.pyt_ansible_excepthook�scC`sz|ddkr�tjjt|ddd��r�d}|drO|d}n#|drrtjj|d�}n|r�tjj|d|�|d<q�ntt|ddd��}|ddkr|dkr�||d<q|d	r�d
|d<qd|d<n|d	rB|dd
krBtdid
d6|dd6��n|drv|ddkrvd|d<t	j
d�ndS(s0Additional parameter validation and reformattingtstatetlinktabsenttpathterrorstsurrogate_or_strictt_original_basenametsrctrecurset	directorytfileRs/recurse option requires state to be 'directory'tmsgthards`The src option requires state to be 'link' or 'hard'.  This will become an error in Ansible 2.10N(slinkR%(slinkR/(tosR&tisdirR	tNonetbasenametjoint	get_stateRRtwarn(tparamsR3t
prev_state((s>/usr/lib/python2.7/site-packages/ansible/modules/files/file.pytadditional_parameter_handling�s*2


#




cC`s�t|dd�}yftjj|�rstjj|�r=dStjj|�rSdStj|�jdkrodSdSdSWn,tk
r�}|j	t	j
kr�dS�nXd	S(
s Find out current state R'R(R$R,iR/R-R%N(R	R0R&tlexiststislinkR1tstattst_nlinktOSErrorterrnotENOENT(R&tb_pathte((s>/usr/lib/python2.7/site-packages/ansible/modules/files/file.pyR51sc
	C`s't}y�x�tj|�D]�\}}}x�||D]�}	tjj||	�}
tjj|
�s�|j�}t|
dd�|d<|tj	||dt�O}|t
|d||�O}q3|j�}t|
dd�|d<|tj	||dt�O}|t
|d||�O}|r3tjj|tj|
��}
tjj|
�r�tjj
|
�rz|t|
||||�O}n|j�}t|
dd�|d<|tj	||dt�O}|t
|d||�O}q�q3q3WqWWn?tk
r"}tdidt|�t|�fd6��nX|S(NR'R(R&texpandRsDCould not recursively set attributes on %s. Original error was: '%s'R.(tFalseR0twalkR&R4R;tcopyR
Rtset_fs_attributes_if_differenttupdate_timestamp_for_filetreadlinktexistsR1trecursive_set_attributestRuntimeErrorR(
RAtfollowt	file_argstmtimetatimetchangedtb_roottb_dirstb_filestb_fsobjtb_fsnamet
tmp_file_argsRB((s>/usr/lib/python2.7/site-packages/ansible/modules/files/file.pyRKJs6,*c
C`s1ii|d6d6i|d6d6}||kr-||dd<||dd<|dkr-|dkr-igd6gd6}t|d	d
�}x�tj|�D]}\}}}x4|D],}	tjj||	�}
|dj|
�q�Wx4|D],}tjj||�}|dj|�q�Wq�W||dd<q-n|S(NR&tbeforetafterR#R%R,tdirectoriestfilesR'R(tpath_content(R	R0RER&R4tappend(
R&R#R8tdifftwalklistRAt	base_pathtsub_foldersR[tfoldert
folderpathtfilenametfilepath((s>/usr/lib/python2.7/site-packages/ansible/modules/files/file.pytinitial_diffus&


c
C`s�|dkrdS|dkr tSy%tj||�}tj|�}WnHttfk
r�}tdid||t|dd�fd6��nX|SdS(NtpreservetnowRs?Error while obtaining timestamp for time %s using format %s: %st	nonstringt
simplereprR.(	R2Rttimetstrptimetmktimet
ValueErrort
OverflowErrorRR
(tformatted_timettime_formattstructtstruct_timeRB((s>/usr/lib/python2.7/site-packages/ansible/modules/files/file.pytget_timestamp_for_time�s'c	C`s!t|dd�}y�|tkrj|tkrjtj�}}tj|�j}tj|�j}d}n�|dkr�|dkr�tStj|�j}tj|�j}|dkr�|}n|tkr�tj�}n|dkr�|}n|tkr
tj�}n||kr&||kr&tS||f}tj	||�|dk	r�d|krgi|d<nd|kr�i|d<n||kr�||dd<||dd<n||kr�||dd<||dd<q�nWn@t
k
r}tdidt|d	d
�d6|d6��nXt
S(
NR'R(RXRYRORPRs4Error while updating modification or access time: %sRiRjR.R&(R	RRkR0R<tst_mtimetst_atimeR2RDtutimeR>RR
tTrue(	R&RORPR^RAtprevious_mtimetprevious_atimetset_timeRB((s>/usr/lib/python2.7/site-packages/ansible/modules/files/file.pyRH�sL			

%cC`s@|dkr|dkrdS|dkr8|dkr8dS|SdS(	NR-R/R,R$RgttouchRh(sfileshards	directoryslink(R2(t	parameterR#((s>/usr/lib/python2.7/site-packages/ansible/modules/files/file.pyt)keep_backward_compatibility_on_timestamps�s
cC`spt|dd�}t}y+t|d��}|jd�}WdQXWntk
rVnXd|krlt}n|S(s2Take a guess as to whether a file is a binary fileR'R(trbi Nt(R	RDtopentreadt	ExceptionRx(R&RAtappears_binarytfthead((s>/usr/lib/python2.7/site-packages/ansible/modules/files/file.pytexecute_diff_peek�s
	cC`s_t|dd�}t|�}i}|dkr9t|d|�}tjs
|dkr�ytj|dt�Wq
tk
r�}t	didt
|�d6��q
Xq
ytj|�Wq
t
k
r	}|jtjkr
t	did	t
|�d6|d
6��q
q
Xn|ji|d
6td6|d6dd
6�n"|ji|d
6td6dd
6�|S(NR'R(R%R,t
ignore_errorsRsrmtree failed: %sR.sunlinking failed: %s R&RQR^R#(R	R5RfRt
check_modetshutiltrmtreeRDR�RR
R0tunlinkR>R?R@tupdateRx(R&RAR8tresultR^RB((s>/usr/lib/python2.7/site-packages/ansible/modules/files/file.pyt
ensure_absent�s(	',"cC`s�t|dd�}t|�}t}i|d6}t|d|d�}t|d|d�}tjs�|dkr�yt|d	�j�t}Wq�t	t
fk
r�}	td
idt|	dd
�d6|d6��q�Xnt
|d|�}
tjtj�}y<tj|||
dt�}|t|d|||
�O}Wn>tk
r}}	|	jrw|dkrwtj|�qwn�nX||d<|
|d<n|S(NR'R(tdesttmodification_timetmodification_time_formattaccess_timetaccess_time_formatR%twbRs!Error, could not touch target: %sRiRjR.R&R|RCRQR^(R	R5RDRtRR�R�tcloseRxR>tIOErrorRR
Rftload_file_common_argumentsR7RGRHt
SystemExittcodeR0tremove(R&RMt
timestampsRAR8RQR�RORPRBR^RN((s>/usr/lib/python2.7/site-packages/ansible/modules/files/file.pyt
execute_touchs8
	
!	

c
C`s\t|dd�}t|�}tjtj�}t|d|d�}t|d|d�}|dkr�|r�|dkr�tjj|�}t	|dd	�}t|�}||d
<q�n|dkr�t
did
||fd6|d
6|d6��nt|d|�}tj|t
|dt
�}	|	t|d
|||�O}	i|d
6|	d6|d6S(NR'R(R�R�R�R�R-R$tstrictR&R/Rs file (%s) is %s, cannot continueR.R#RCRQR^(sfileshard(R	R5RR�R7RtR0R&trealpathR
RRfRGRDRH(
R&RMR�RAR8RNRORPR^RQ((s>/usr/lib/python2.7/site-packages/ansible/modules/files/file.pytensure_file_attributes=s$c	C`s&t|dd�}t|�}tjtj�}t|d|d�}t|d|d�}|r�|dkr�tjj|�}t	|dd�}||d	<t|�}nt
}	t|d
|�}
|dkrztjr�it
d6|
d
6Sd}y,x%|jd�jd�D]}dj||g�}tjj|�sM|jd�}nt|dd�}
tjj|
�sytj|
�t
}	Wn=tk
r�}|jtjko�tjj|
�s��q�nX|j�}||d	<tj||	|
dt
�}	|	t|d	|||
�O}	qqWWn@tk
r`}tdid|t	|�fd6|d	6��nXi|d	6|	d6|
d
6S|d
kr�tdid||fd6|d	6��ntj||	|
dt
�}	|	t|d	|||
�O}	|r
|	t|||||�O}	ni|d	6|	d6|
d
6S(NR'R(R�R�R�R�R$R�R&R,R%RQR^tt/RCRs/There was an issue creating %s as requested: %sR.s%s already exists as a %s(R	R5RR�R7RtR0R&R�R
RDRfR�RxtstriptsplitR4tisabstlstripRJtmkdirR>R?tEEXISTR1RFRGRHR�RRK(R&RMR+R�RAR8RNRORPRQR^tcurpathtdirnamet	b_curpathtexRWRB((s>/usr/lib/python2.7/site-packages/ansible/modules/files/file.pytensure_directoryWs\
	

$

(c
C`s�t|dd�}t|dd�}t|�}t|d|d�}t|d|d�}	|dkr�|r�ttjj|�dd�}t|dd�}q�ntjj|�r�tjj	|�r�|}
n$tjj
|�}t|dd�}
tjj|
|�}t|dd�}
|rdtjj|
�rdt
did	|d
6|d6|d6��n|d
kr�|s�t
did||fd
6|d6��qtj|�rt
did|d
6|d6��qn=|d#kr|rt
did||fd
6|d6��nt|d|�}t}|dkr@t}nZ|dkr�tj|�}||kr�t|dd�|dd<||dd<t}q�n�|dkr�t}|s�t
didd
6|d6|d6��q�n�|dkrt}|s�t
didd
6|d6|d6��q�n{|d
krvt}tjj|�r�|sst
didd
6|d6|d6��qsq�n$t
didd
6|d6|d6��|rtjr|dkr�ttjj�jtjj
|�tdtj�tj�f�g�}y@|d
krtj|�ntj||�tj||�Wq�tk
r�}tjj|�rstj|�nt
didt|dd�d
6|d6��q�Xqytj||�Wqtk
r�}t
didt|dd�d
6|d6��qXntjr=tjj|�r=i|d6|d6|d6|d 6Stjtj�}|r�tjj|�r�tjj|d�r�tjd!�n8tj |||d"t�}|t!|d||	|�O}i|d6|d6|d6|d 6S($NR'R(R�R�R�R�R�RsRsrc file does not exist, use "force=yes" if you really want to create the link: %sR.R&R*R,s-refusing to convert from %s to symlink for %ss5the directory %s is not empty, refusing to convert itR-R/R$R%RXRYs5Cannot link because a hard link exists at destinationR�s0Cannot link because a file exists at destinationsunexpected position reacheds
.%s.%s.tmpsError while replacing: %sRiRjsError while linking: %sRQR^sgCannot set fs attributes on a non-existent symlink target. follow should be set to False to avoid this.RC(sfileshard("R	R5RtR2R
R0R&R�R;R1R�R4RJRtlistdirRfRDRxRIRR�tseptgetpidRktrmdirtsymlinktrenameR>R�R�R7R6RGRH(R&R*RMtforceR�RAtb_srcR8RORPtrelpatht	b_relpathtabsrctb_absrcR^RQt	b_old_srct	b_tmppathRBRN((s>/usr/lib/python2.7/site-packages/ansible/modules/files/file.pytensure_symlink�s�%		$7 /c	C`s�t|dd�}t|dd�}t|�}tjtj�}t|d|d�}	t|d|d�}
|dkr�tdidd	6��ntj	j
|�s�tdid
d	6|d6|d6��nt|d
|�}t}|dkr�t
}n�|dkrVtj|�}
|
|kr�t|
dd�|dd<||dd<t
}q�n`|d
kr�tj|�jtj|�jks�t
}|s�tdidd	6|d6|d6��q�q�n�|dkrt
}|s�tdid|d	6|d6|d6��q�n�|dkr�t
}tj	j
|�r�tj|�jtj|�jkr_i|d6td6S|s�tdidd	6|d6|d6��q�q�n$tdidd	6|d6|d6��|rdtjrd|dkr
ttj	j�jtj	j|�tdtj�tj�f�g�}y�|dkr�tj	j
|�r�ytj|�Wq~tk
rz}|jtjkr{�q{q~Xq�ntj||�tj||�Wqatk
r}tj	j
|�r�tj|�ntdidt|dd�d	6|d6��qaXqdytj||�Wqdtk
r`}tdidt|dd�d	6|d6��qdXntjr�tj	j
|�r�i|d6|d6|d6|d 6Stj|||d!t�}|t|d|	|
|�O}i|d6|d6|d6|d 6S("NR'R(R�R�R�R�Rs*src is required for creating new hardlinksR.ssrc does not existR�R*R/R%R$R�RXRYs6Cannot link, different hard link exists at destinationR-s%Cannot link, %s exists at destinationR,R&RQs6Cannot link: different hard link exists at destinationsunexpected position reacheds
.%s.%s.tmpsError while replacing: %sRiRjsError while linking: %sR^RC( R	R5RR�R7RtR2RR0R&RJRfRDRxRIR
R<tst_inoR�R�R4R�R�RkR�R>R?R@R$R�RGRH(R&R*RMR�R�RAR�R8RNRORPR^RQR�R�RB((s>/usr/lib/python2.7/site-packages/ansible/modules/files/file.pytensure_hardlinks�'	$$$7 c
C`s�tdtdtddddddd	d
dg�dtddd
tdddg�dtdd�dtdddt�dtdddt�dtdddt�dtdd�dtdd�dtdd�dtdddd�dtdd�dtdddd��dtdt�att_ttj	�tj	}|d}|d}|d}|d}|d}|d}i}t
|d|�|d<|d|d<t
|d|�|d<|d|d<|ddk	rtt
|d d!��}tjd|d"td#|�n|dkr-t|||�}	n�|dkrQt||||�}	n�|d
krxt|||||�}	nc|d	kr�t|||||�}	n<|dkr�t|||�}	n|dkr�t|�}	ntj|	�dS($Nt
argument_specR#ttypetstrtchoicesR%R,R-R/R$R|R&trequiredtaliasesR�tnameR)R+tbooltdefaultR�RMt
_diff_peekR*R�R�s
%Y%m%d%H%M.%SR�R�tadd_file_common_argstsupports_check_modeR'R(RQR�(RtdictRxRDRR"Rt
excepthookR9R7R~R2R�R	t	exit_jsonR�R�R�R�R�R�(
R7R#R+R�RMR&R*R�R�R�((s>/usr/lib/python2.7/site-packages/ansible/modules/files/file.pytmainms\'!		
	





t__main__(,t
__future__RRRR�t
__metaclass__tANSIBLE_METADATAt
DOCUMENTATIONtEXAMPLEStRETURNR?R0R�RRktansible.module_utils.basicRtansible.module_utils._textR	R
R2RR�RRtobjectRR"R9R5RKRfRtRHR~R�R�R�R�R�R�R�R�R(((s>/usr/lib/python2.7/site-packages/ansible/modules/files/file.pyt<module>sH


j[		3		+	 	:					'		G	w	X	>

Anons79 File Manager Version 1.0, Coded By Anons79
Email: [email protected]