Anons79 Mini Shell

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

�
�Udac@`sddlmZmZmZeZidd6dgd6dd6ZdZd	Zdd
l	Z	dd
l
Z
dd
lZdd
lZdd
l
Z
dd
lZddlmZmZddlmZmZdd
lmZdefd��YZdefd��YZd�Zedkre�nd
S(i(tabsolute_importtdivisiontprint_functions1.1tmetadata_versiontpreviewtstatust	communitytsupported_bys

---
module: cron
short_description: Manage cron.d and crontab entries
description:
  - Use this module to manage crontab and environment variables entries. This module allows
    you to create environment variables and named crontab entries, update, or delete them.
  - 'When crontab jobs are managed: the module includes one line with the description of the
    crontab entry C("#Ansible: <name>") corresponding to the "name" passed to the module,
    which is used by future ansible/module calls to find/check the state. The "name"
    parameter should be unique, and changing the "name" value will result in a new cron
    task being created (or a different one being removed).'
  - When environment variables are managed, no comment line is added, but, when the module
    needs to find/check the state, it uses the "name" parameter to find the environment
    variable definition line.
  - When using symbols such as %, they must be properly escaped.
version_added: "0.9"
options:
  name:
    description:
      - Description of a crontab entry or, if env is set, the name of environment variable.
      - Required if C(state=absent).
      - Note that if name is not set and C(state=present), then a
        new crontab entry will always be created, regardless of existing ones.
      - This parameter will always be required in future releases.
    type: str
  user:
    description:
      - The specific user whose crontab should be modified.
      - When unset, this parameter defaults to using C(root).
    type: str
  job:
    description:
      - The command to execute or, if env is set, the value of environment variable.
      - The command should not contain line breaks.
      - Required if C(state=present).
    type: str
    aliases: [ value ]
  state:
    description:
      - Whether to ensure the job or environment variable is present or absent.
    type: str
    choices: [ absent, present ]
    default: present
  cron_file:
    description:
      - If specified, uses this file instead of an individual user's crontab.
      - If this is a relative path, it is interpreted with respect to I(/etc/cron.d).
      - If it is absolute, it will typically be I(/etc/crontab).
      - Many linux distros expect (and some require) the filename portion to consist solely
        of upper- and lower-case letters, digits, underscores, and hyphens.
      - To use the C(cron_file) parameter you must specify the C(user) as well.
    type: str
  backup:
    description:
      - If set, create a backup of the crontab before it is modified.
        The location of the backup is returned in the C(backup_file) variable by this module.
    type: bool
    default: no
  minute:
    description:
      - Minute when the job should run ( 0-59, *, */2, etc )
    type: str
    default: "*"
  hour:
    description:
      - Hour when the job should run ( 0-23, *, */2, etc )
    type: str
    default: "*"
  day:
    description:
      - Day of the month the job should run ( 1-31, *, */2, etc )
    type: str
    default: "*"
    aliases: [ dom ]
  month:
    description:
      - Month of the year the job should run ( 1-12, *, */2, etc )
    type: str
    default: "*"
  weekday:
    description:
      - Day of the week that the job should run ( 0-6 for Sunday-Saturday, *, etc )
    type: str
    default: "*"
    aliases: [ dow ]
  reboot:
    description:
      - If the job should be run at reboot. This option is deprecated. Users should use special_time.
    version_added: "1.0"
    type: bool
    default: no
  special_time:
    description:
      - Special time specification nickname.
    type: str
    choices: [ annually, daily, hourly, monthly, reboot, weekly, yearly ]
    version_added: "1.3"
  disabled:
    description:
      - If the job should be disabled (commented out) in the crontab.
      - Only has effect if C(state=present).
    type: bool
    default: no
    version_added: "2.0"
  env:
    description:
      - If set, manages a crontab's environment variable.
      - New variables are added on top of crontab.
      - C(name) and C(value) parameters are the name and the value of environment variable.
    type: bool
    default: no
    version_added: "2.1"
  insertafter:
    description:
      - Used with C(state=present) and C(env).
      - If specified, the environment variable will be inserted after the declaration of specified environment variable.
    type: str
    version_added: "2.1"
  insertbefore:
    description:
      - Used with C(state=present) and C(env).
      - If specified, the environment variable will be inserted before the declaration of specified environment variable.
    type: str
    version_added: "2.1"
requirements:
  - cron
author:
    - Dane Summers (@dsummersl)
    - Mike Grozak (@rhaido)
    - Patrick Callahan (@dirtyharrycallahan)
    - Evan Kaufman (@EvanK)
    - Luca Berruti (@lberruti)
s
- name: Ensure a job that runs at 2 and 5 exists. Creates an entry like "0 5,2 * * ls -alh > /dev/null"
  cron:
    name: "check dirs"
    minute: "0"
    hour: "5,2"
    job: "ls -alh > /dev/null"

- name: 'Ensure an old job is no longer present. Removes any job that is prefixed by "#Ansible: an old job" from the crontab'
  cron:
    name: "an old job"
    state: absent

- name: Creates an entry like "@reboot /some/job.sh"
  cron:
    name: "a job for reboot"
    special_time: reboot
    job: "/some/job.sh"

- name: Creates an entry like "PATH=/opt/bin" on top of crontab
  cron:
    name: PATH
    env: yes
    job: /opt/bin

- name: Creates an entry like "APP_HOME=/srv/app" and insert it after PATH declaration
  cron:
    name: APP_HOME
    env: yes
    job: /srv/app
    insertafter: PATH

- name: Creates a cron file under /etc/cron.d
  cron:
    name: yum autoupdate
    weekday: "2"
    minute: "0"
    hour: "12"
    user: root
    job: "YUMINTERACTIVE=0 /usr/sbin/yum-autoupdate"
    cron_file: ansible_yum-autoupdate

- name: Removes a cron file from under /etc/cron.d
  cron:
    name: "yum autoupdate"
    cron_file: ansible_yum-autoupdate
    state: absent

- name: Removes "APP_HOME" environment variable from crontab
  cron:
    name: APP_HOME
    env: yes
    state: absent
N(t
AnsibleModuletget_platform(tto_bytest	to_native(tshlex_quotetCronTabErrorcB`seZRS((t__name__t
__module__(((s?/usr/lib/python2.7/site-packages/ansible/modules/system/cron.pyR
�stCronTabcB`s
eZdZddd�Zd�Zd�Zdd�Zd�Zd�Z	d�Z
d�Zd	�Zd
�Z
ddd�Zd�Zd
�Zd�Zd�Zd�Zdd�Zd�Zd�Zd�Zd�Zd�Zd�Zd�Zd�Zd�ZRS(s�
        CronTab object to write time based crontab file

        user      - the user of the crontab (defaults to root)
        cron_file - a cron file under /etc/cron.d, or an absolute path
    cC`s�||_||_tj�dk|_d|_d|_d|_|jj	ddt
�|_|r�tjj
|�r�||_t|dd�|_q�tjjd|�|_tjjdt|dd��|_n	d|_|j�dS(	Nis
#Ansible: ttcrontabtrequiredterrorstsurrogate_or_stricts/etc/cron.d(tmoduletusertostgetuidtroottNonetlinestansiblet
n_existingtget_bin_pathtTruetcron_cmdtpathtisabst	cron_fileR
tb_cron_filetjointread(tselfRRR$((s?/usr/lib/python2.7/site-packages/ansible/modules/system/cron.pyt__init__�s						'	c	
C`s�g|_|jr�yMt|jd�}t|j�dd�|_|jj�|_|j�Wq�t	k
rsdSt
k
r�tdtj
�d��q�Xn
|jj|j�dt�\}}}|dkr�|dkr�td��n||_|j�}d}x�|D]�}|d	ks[tjd
|�rntjd|�rntjd|�rn|jj|�n1tj|�d
}tj|d|jd�|_|d7}qWdS(NtrbRRsUnexpected error:ituse_unsafe_shellisUnable to read crontabis8# DO NOT EDIT THIS FILE - edit the master and reinstall.s# \(/tmp/.*installed on.*\)s# \(.*version.*\)s[
]?R(RR$topenR%RR'Rt
splitlinestclosetIOErrort	ExceptionR
tsystexc_infoRtrun_commandt_read_user_executeR tretmatchtappendtescapetsub(	R(tftrctoutterrRtcounttltpattern((s?/usr/lib/python2.7/site-packages/ansible/modules/system/cron.pyR'�s2		

 '	
cC`s!t|j�dkrtStSdS(Ni(tlenRR tFalse(R(((s?/usr/lib/python2.7/site-packages/ansible/modules/system/cron.pytis_empty!scC`s@|rt|d�}na|jr6t|jd�}nCtjdd�\}}tj|tdd��tj|d�}|j	t
|j���|j�|r�dS|js|j
j|j|�dt�\}}}tj|�|dkr|j
jd	|�qn|j
j�r<|jr<|j
j|jt�ndS(
sI
        Write the crontab to the system. Saves all information.
        twbtprefixRt0644iNR+itmsg(R,R$R%ttempfiletmkstempRtchmodtinttfdopentwriteR
trenderR.RR3t_write_executeR tunlinkt	fail_jsontselinux_enabledtset_default_selinux_contextRB(R(tbackup_filetfilehtfiledR"R;R<R=((s?/usr/lib/python2.7/site-packages/ansible/modules/system/cron.pyRM's$	
	*
cC`sd|j|fS(Ns%s%s(R(R(tname((s?/usr/lib/python2.7/site-packages/ansible/modules/system/cron.pyt
do_commentHscC`s1|jj|j|��|jjd|�dS(Ns%s(RR7RX(R(RWtjob((s?/usr/lib/python2.7/site-packages/ansible/modules/system/cron.pytadd_jobKscC`s|j|||j�S(N(t_update_jobt
do_add_job(R(RWRY((s?/usr/lib/python2.7/site-packages/ansible/modules/system/cron.pyt
update_jobRscC`s"|j|�|jd|�dS(Ns%s(R7(R(RtcommentRY((s?/usr/lib/python2.7/site-packages/ansible/modules/system/cron.pyR\Us
cC`s|j|d|j�S(NR(R[t
do_remove_job(R(RW((s?/usr/lib/python2.7/site-packages/ansible/modules/system/cron.pyt
remove_jobZscC`sdS(N(R(R(RR^RY((s?/usr/lib/python2.7/site-packages/ansible/modules/system/cron.pyR_]scC`s�|p	|s#|jjd|�dS|r2|}n|rA|}n|j|�}t|�dkr�|ry|dd}n|r�|d}n|jj||�dS|jjdd|�dS(NiiRGsVariable named '%s' not found.(Rtinserttfind_envRARRQ(R(tdecltinsertaftertinsertbeforet
other_namet
other_decltindex((s?/usr/lib/python2.7/site-packages/ansible/modules/system/cron.pytadd_env`s 		
cC`s|j|||j�S(N(t_update_envt
do_add_env(R(RWRc((s?/usr/lib/python2.7/site-packages/ansible/modules/system/cron.pyt
update_envtscC`s|j|�dS(N(R7(R(RRc((s?/usr/lib/python2.7/site-packages/ansible/modules/system/cron.pyRkwscC`s|j|d|j�S(NR(Rjt
do_remove_env(R(RW((s?/usr/lib/python2.7/site-packages/ansible/modules/system/cron.pyt
remove_envzscC`sdS(N(R(R(RRc((s?/usr/lib/python2.7/site-packages/ansible/modules/system/cron.pyRm}scC`sZytj|j�tSWn;tk
r,tStk
rUtdtj	�d��nXdS(NsUnexpected error:i(
RRPR$R tOSErrorRBR0R
R1R2(R(((s?/usr/lib/python2.7/site-packages/ansible/modules/system/cron.pytremove_job_file�s

cC`sed}xt|jD]i}|dk	rA||kr8||gSd}qtjd|j|�rtjd|jd|�}qqW|rax�t|j�D]�\}}||kr�tjd|j|j|d�s�|jj||j|��|j||t	gS|rZ|j|d|jd�krZ|j|�|j|d<|j|d|t	gSq�q�WngS(Ns%sRi(
RRR5R6RR9t	enumerateRaRXR (R(RWRYR^R?ti((s?/usr/lib/python2.7/site-packages/ansible/modules/system/cron.pytfind_job�s$
	#$&"cC`sDx=t|j�D],\}}tjd||�r||gSqWgS(Ns^%s=(RqRR5R6(R(RWRhR?((s?/usr/lib/python2.7/site-packages/ansible/modules/system/cron.pyRb�sc	
	C`s�|jd�}|rd}	nd}	|r^|jrJd|	||j|fSd|	||fSnI|jr�d|	||||||j|fSd|	||||||fSdS(Ns
t#Rs%s@%s %s %ss%s@%s %ss%s%s %s %s %s %s %s %ss%s%s %s %s %s %s %s(tstripR$R(
R(tminutethourtdaytmonthtweekdayRYtspecialtdisabledtdisable_prefix((s?/usr/lib/python2.7/site-packages/ansible/modules/system/cron.pytget_cron_job�s			#cC`s]g}xP|jD]E}tjd|j|�r|jtjd|jd|��qqW|S(Ns%sR(RR5R6RR7R9(R(tjobnamesR?((s?/usr/lib/python2.7/site-packages/ansible/modules/system/cron.pytget_jobnames�s
*cC`sMg}x@|jD]5}tjd|�r|j|jd�d�qqW|S(Ns^\S+=t=i(RR5R6R7tsplit(R(tenvnamesR?((s?/usr/lib/python2.7/site-packages/ansible/modules/system/cron.pytget_envnames�s
!cC`s�|j|�}g}d}xX|jD]M}|dk	rP||||�d}q%||kre|}q%|j|�q%W||_t|�dkr�tStSdS(Ni(RXRRR7RAR RB(R(RWRYtaddlinesfunctiontansiblenametnewlinesR^R?((s?/usr/lib/python2.7/site-packages/ansible/modules/system/cron.pyR[�s			cC`sZg}xD|jD]9}tjd||�r<|||�q|j|�qW||_dS(Ns^%s=(RR5R6R7(R(RWRctaddenvfunctionR�R?((s?/usr/lib/python2.7/site-packages/ansible/modules/system/cron.pyRj�scC`sVg}x|jD]}|j|�qWdj|�}|rR|jd�d}n|S(sD
        Render this crontab as it would be in the crontab.
        s
s
(RR7R&trstrip(R(tcronstcrontresult((s?/usr/lib/python2.7/site-packages/ansible/modules/system/cron.pyRN�scC`s�d}|jr�tj�dkrAdt|j�t|j�fStj�dkrsdt|j�t|j�fStj�dkr�d|jdt|j�fStjtj��d	|jkr�d
t|j�}q�nd|j|dfS(s@
        Returns the command line for reading a crontab
        RtSunOSssu %s -c '%s -l'tAIXs%s -l %ssHP-UXs%s %s %ss-lis-u %s(	RtplatformtsystemRR!tpwdtgetpwuidRR(R(R((s?/usr/lib/python2.7/site-packages/ansible/modules/system/cron.pyR4�s	  "cC`s�d}|jr�tj�d	krYdt|j�t|�t|j�|jt|�fStjtj��d|jkr�dt|j�}q�nd|j|t|�fS(
s?
        Return the command line for writing a crontab
        RR�sHP-UXR�s chown %s %s ; su '%s' -c '%s %s'is-u %ss%s %s %s(sSunOSsHP-UXsAIX(	RR�R�RR!R�R�RR(R(R"R((s?/usr/lib/python2.7/site-packages/ansible/modules/system/cron.pyROs	5"N(RRt__doc__RR)R'RCRMRXRZR]R\R`R_RiRlRkRnRmRpRsRbR~R�R�R[RjRNR4RO(((s?/usr/lib/python2.7/site-packages/ansible/modules/system/cron.pyR�s6	$	!											
									
	c 'C`s#	tdtdtdd�dtdd�dtddddg�d	tdd�d
tddddd
ddg�dtdddt�dtdddd�dtdddd�dtddddddg�dtdddd�dtddddddg�dtdddt�dtddd
ddddddd g�d!tdddt�d"tdd�d#tdd�d$tdd��d%td&ddgd#d$gg�}|jd}|jd}|jd}|jd	}|jd
}|jd}|jd}|jd}|jd}	|jd}
|jd}|jd}|jd}
|jd!}|jd"}|jd#}|jd$}|dk}t}t�}t�}|r�tjj|�}t	j
d'|t	j�s�|jd(|d)�q�ntj
td*d+��t|||�}|jd,|�|sK|jd-d.d/d0�n|rj|jd-d1d/d0�n|jr�t�}|j|d2<|jr�|j|d3<q�|jr�d4|j|d3<q�d5|d3<n|
s�|rtg|||	|
|gD]}|dk^q�kr|jd-d6�n|
s+|rMt�d7krM|jd-d8�n|ru|ru|su|jd-d9�qun|dkr�|r�|jd-d:�n|s�|r�|r�|r�|jd-d;�n|r�d}
n|r
|jr
tjd<d5�\}}|j|�n|jr�|r�|r�|jrDd=|d><d?|d@<n	t�}|jrntjj|j�}n|j�}|jdA|d	|d
|dB|�n|r�dC|kr�|jd-dD�ndE||f}|j |�}|rUt!|�dFkr|j"|||�t}nt!|�dFkr}|dG|kr}|j#||�t}q}q�t!|�dFkr�|j$|�t}q�nD|r�x:dHdIgD],}||j%dJ�kr�|jdK�Pq�q�W|j&|||	|
|||
|�}|j'||�}t!|�dFkr$|j(||�t}nt!|�dFkr_|dG|kr_|j)||�t}nt!|�dLkr�|j)||�t}q�n7|j'|�}t!|�dFkr�|j*|�t}n|r
|jd=kr
|jj+dH�p�|jj+dI�s
t}q
ntdM|j,�dN|j-�dO|dA|�}|r�|jsS|j�n|jr�|j.�|d><|jr�|j|d@<n'|jr�d4|j|d@<n
d5|d@<||dB<q�n|r�|jr�|r�||dP<q�tj/|�n|r	||d	<n|j|�|jd-dQ�dS(RNt
argument_specRWttypetstrRRYtaliasestvalueR$tstatetdefaulttpresenttchoicestabsenttbackuptboolRvt*RwRxtdomRyRztdowtreboottspecial_timetyearlytannuallytmonthlytweeklytdailythourlyR|tenvRdRetsupports_check_modetmutually_exclusives
^[A-Z0-9_-]+$s3Filename portion of cron_file ("%s") should consistsJ solely of upper- and lower-case letters, digits, underscores, and hyphenst022iscron instantiated - name: "%s"RGs9The 'name' parameter will be required in future releases.tversions2.12s]The 'reboot' parameter will be removed in future releases. Use 'special_time' option instead.tbeforet
before_headerscrontab for user "%s"Rs6You must specify time and date fields or special time.R�s4Solaris does not support special_time=... or @reboots@To use cron_file=... parameter you must specify user=... as wells<You must specify 'job' to install a new cron job or variablesCInsertafter and insertbefore parameters are valid only with env=yesRERtafters	/dev/nulltafter_headertchangedtdifft s%Invalid name for environment variables%s="%s"iis
s
s
s"Job should not contain line breaksitjobstenvstwarningsRTsUnable to execute cron task.(0RtdictRBR tparamstlistRR"tbasenameR5tsearchtIR7tumaskRKRtdebugt	deprecatet_diffRR$RRQR	Rt
check_modeRHRIRMtisfileRpt	exit_jsonRbRARiRlRnRuR~RsRZR]R`tendswithR�R�RNRP( RRWRRYR$R�R�RvRwRxRyRzR�R�R|R�RdRet
do_installR�tres_argsR�tcron_file_basenameRR�txtbackuphRTRctold_decltchartold_job((s?/usr/lib/python2.7/site-packages/ansible/modules/system/cron.pytmains6!*	
















		
	
	
		
		
4		

		%	"

$	"	
	$		
			



t__main__(t
__future__RRRR�t
__metaclass__tANSIBLE_METADATAt
DOCUMENTATIONtEXAMPLESRR�R�R5R1RHtansible.module_utils.basicRR	t+ansible.module_utils.common.text.convertersR
Rtansible.module_utils.six.movesRR0R
tobjectRR�R(((s?/usr/lib/python2.7/site-packages/ansible/modules/system/cron.pyt<module>s*


�7�>	�

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