Anons79 Mini Shell

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

�
�Udac@`s�ddlmZmZmZeZidd6dgd6dd6ZdZd	Zdd
l	Z	dd
l
Z
dd
lZddlm
Z
mZddlmZdd
lmZmZddlmZdefd��YZd�Zedkr�e�nd
S(i(tabsolute_importtdivisiontprint_functions1.1tmetadata_versiontstableinterfacetstatustcoretsupported_bys�
---
module: sysctl
short_description: Manage entries in sysctl.conf.
description:
    - This module manipulates sysctl entries and optionally performs a C(/sbin/sysctl -p) after changing them.
version_added: "1.0"
options:
    name:
        description:
            - The dot-separated path (aka I(key)) specifying the sysctl variable.
        required: true
        aliases: [ 'key' ]
    value:
        description:
            - Desired value of the sysctl key.
        aliases: [ 'val' ]
    state:
        description:
            - Whether the entry should be present or absent in the sysctl file.
        choices: [ "present", "absent" ]
        default: present
    ignoreerrors:
        description:
            - Use this option to ignore errors about unknown keys.
        type: bool
        default: 'no'
    reload:
        description:
            - If C(yes), performs a I(/sbin/sysctl -p) if the C(sysctl_file) is
              updated. If C(no), does not reload I(sysctl) even if the
              C(sysctl_file) is updated.
        type: bool
        default: 'yes'
    sysctl_file:
        description:
            - Specifies the absolute path to C(sysctl.conf), if not C(/etc/sysctl.conf).
        default: /etc/sysctl.conf
    sysctl_set:
        description:
            - Verify token value with the sysctl command and set with -w if necessary
        type: bool
        default: 'no'
        version_added: 1.5
author: "David CHANIAL (@davixx) <[email protected]>"
s�
# Set vm.swappiness to 5 in /etc/sysctl.conf
- sysctl:
    name: vm.swappiness
    value: '5'
    state: present

# Remove kernel.panic entry from /etc/sysctl.conf
- sysctl:
    name: kernel.panic
    state: absent
    sysctl_file: /etc/sysctl.conf

# Set kernel.panic to 3 in /tmp/test_sysctl.conf
- sysctl:
    name: kernel.panic
    value: '3'
    sysctl_file: /tmp/test_sysctl.conf
    reload: no

# Set ip forwarding on in /proc and verify token value with the sysctl command
- sysctl:
    name: net.ipv4.ip_forward
    value: '1'
    sysctl_set: yes

# Set ip forwarding on in /proc and in the sysctl file and reload if necessary
- sysctl:
    name: net.ipv4.ip_forward
    value: '1'
    sysctl_set: yes
    state: present
    reload: yes
N(tget_platformt
AnsibleModule(tstring_types(tBOOLEANS_FALSEt
BOOLEANS_TRUE(t	to_nativetSysctlModulecB`s�eZidd6dd6dd6Zd�Zd�Zd�Zd�Zd�Zd	�Zd
�Z	d�Z
d�Zd
�Zd�Z
RS(tCtLANGtLC_ALLtLC_MESSAGEScC`s�||_|jj|_|jjddt�|_|jd|_d|_d|_	g|_
i|_t|_
t|_t|_|j�dS(Ntsysctltrequiredtsysctl_file(tmoduletparamstargstget_bin_pathtTruet
sysctl_cmdRtNonet
proc_valuet
file_valuet
file_linestfile_valuestFalsetchangedtset_proct
write_filetprocess(tselfR((sA/usr/lib/python2.7/site-packages/ansible/modules/system/sysctl.pyt__init__us								c	C`s�t�j�|_|jdj�|jd<|j|jd�|jd<|jd}|j|�|_|j�||j	kr�d|j	|<n|j�|j	|dkr�|jddkr�t|_
t|_n�|j	|dkr|jddkrt|_
n�|j	|r=|jddkr=t|_
t|_n�|j	||jdkrlt|_
t|_nS|jdr�|jdkr�t|_
q�|j|j|jd�s�t|_
q�n|jdr.|jddkr.|jdkr�t|_
q.|j|j|jd�s.t|_
t|_q.n|jjs�|jrP|j�n|j
rs|jdrs|j�n|jr�|j|jd|jd�q�ndS(Ntnametvaluetstatetpresenttabsenttreloadt
sysctl_set(RtlowertplatformRtstript_parse_valuetget_token_curr_valueRtread_sysctl_fileR Rt	fix_linesRR"R$R!t_values_is_equalR#Rt
check_modetwrite_sysctlt
reload_sysctltset_token_value(R&tthisname((sA/usr/lib/python2.7/site-packages/ansible/modules/system/sysctl.pyR%�sL


&	& 		
 		

	cC`s�|dks|dkrtS|j�}|j�}t|�t|�krPtStgt||�D]\}}||krc|^qc�t|�kS(s�Expects two string values. It will split the string by whitespace
        and compare each value. It will return True if both lists are the same,
        contain the same elements and the same order.N(RR!tsplittlentzip(R&tatbtitj((sA/usr/lib/python2.7/site-packages/ansible/modules/system/sysctl.pyR6�scC`s�|dkrdSt|t�r0|r)dSdSnLt|t�rx|j�tkrUdS|j�tkrkdS|j�Sn|SdS(Ntt1t0(Rt
isinstancetboolR
R/RRR1(R&R)((sA/usr/lib/python2.7/site-packages/ansible/modules/system/sysctl.pyR2�s
cC`s"d}tj||tj�dk	S(NsG^sysctl: setting key "[^"]+": (Invalid argument|Read-only file system)$(tretsearcht	MULTILINER(R&terrterrors_regex((sA/usr/lib/python2.7/site-packages/ansible/modules/system/sysctl.pyt_stderr_failed�scC`st|jdkr%d|j|f}nd|j|f}|jj|d|j�\}}}|dkrldS|SdS(Ntopenbsds%s -n %ss%s -e -n %stenviron_updatei(R0RRtrun_commandtLANG_ENVR(R&ttokentthiscmdtrctoutRK((sA/usr/lib/python2.7/site-packages/ansible/modules/system/sysctl.pyR3�s$cC`s8t|j��dkr)d|d}n|jdkrQd|j||f}n||jdkr�d}|jdr|d}nd	|j|||f}n5d}|jdr�d
}nd|j|||f}|jj|d|j�\}}}|dks|j|�r0|jj	d
d|||f�n|SdS(Nit"RNs%s %s=%stfreebsdRCtignoreerrorss-is%s %s %s=%ss-es%s %s -w %s=%sROtmsgssetting %s failed: %s(
R=R<R0RRRRPRQRMt	fail_json(R&RRR)RStignore_missingRTRURK((sA/usr/lib/python2.7/site-packages/ansible/modules/system/sysctl.pyR:s"
	
	$$cC`s�|jdkr6|jjdd|j�\}}}n|jdkr�x[|jj�D]J\}}d}||jdkrU|j||�}|dkr�Pq�qUqUW|dkr�|jddkr�|j|jd|jd	�}ndS|jd
|j	g}|jdr|j
dd
�n|jj|d|j�\}}}|dks]|j|�r�|jjddt
|�t
|��ndS(NRWs/etc/rc.d/sysctl reloadRORNiR(R*R+R)s-pRXis-eRYsFailed to reload sysctl: %s(R0RRPRQR titemsRR:RRtinsertRMRZR
(R&RTRURKtktvtsysctl_args((sA/usr/lib/python2.7/site-packages/ansible/modules/system/sysctl.pyR9s$'#
$cC`s'g}tjj|j�r�y+t|jd��}|j�}WdQXWq�tk
r�}|jjddt	|j�t	|�f�q�Xnx�|D]�}|j
�}|jj|�|s�|j
d�s�d|kr�q�n|jdd�\}}|j
�}|j
�}|j
�|j|<q�WdS(	NtrRYsFailed to open %s: %st#t;t=i(RbRc(tostpathtisfileRtopent	readlinestIOErrorRRZR
R1Rtappendt
startswithR<R (R&tlinest	read_filetetlineR^R_((sA/usr/lib/python2.7/site-packages/ansible/modules/system/sysctl.pyR4=s 3
"cC`s�g}g|_x |jD]}|j�sM|j�jd
�sMd|krc|jj|�qn|j�}|jdd�\}}|j�}|j�}||kr|j|�||jdkr|jddkr+d||jd	f}|jj|�q+q.d||f}|jj|�qqW|jd|kr�|jddkr�d|jd|jd	f}|jj|�ndS(NRbRcRdiR(R*R+s%s=%s
R)(RbRc(tfixed_linesRR1RlRkR<R(R&tcheckedRpttmplineR^R_tnew_line((sA/usr/lib/python2.7/site-packages/ansible/modules/system/sysctl.pyR5Us*	.
&cC`s�tjddtjj|j��\}}t|d�}y/x(|jD]}|j|j	�d�qFWWn6t
k
r�}|jjdd|t
|�f�nX|j�|j�|jj||j�dS(Ns.confs.ansible_m_sysctl_tws
RYsFailed to write to file %s: %s(ttempfiletmkstempReRftdirnameRRhRqtwriteR1RjRRZR
tflushtclosetatomic_move(R&tfdttmp_pathtftlRo((sA/usr/lib/python2.7/site-packages/ansible/modules/system/sysctl.pyR8os*'

(t__name__t
__module__RQR'R%R6R2RMR3R:R9R4R5R8(((sA/usr/lib/python2.7/site-packages/ansible/modules/system/sysctl.pyRos		:			
	
		%		cC`s�tdtdtddgdt�dtddgdtdd	�d
tddd
ddg�dtdtdd�dtdtdd�dtdtdd�dtdddd��dtdd
ddgfg�}|jddkr�|jdd�n|jd
dkr1|jddkr1|jdd�n|jddkrW|jdd�n|jd
dkr�|jddkr�|jdd�nt|�}|jd|j	�dS(Nt
argument_specR(taliasestkeyRR)tvalttypetstrR*tdefaultR+tchoicesR,R-RGR.RXRs/etc/sysctl.confRftsupports_check_modetrequired_ifRYsname cannot be Nonesvalue cannot be NoneRCsname cannot be blanksvalue cannot be blankR"(
R	tdictRR!RRRZRt	exit_jsonR"(Rtresult((sA/usr/lib/python2.7/site-packages/ansible/modules/system/sysctl.pytmain�s*&&t__main__(t
__future__RRRR�t
__metaclass__tANSIBLE_METADATAt
DOCUMENTATIONtEXAMPLESReRHRvtansible.module_utils.basicRR	tansible.module_utils.sixR
t)ansible.module_utils.parsing.convert_boolRRtansible.module_utils._textR
tobjectRR�R�(((sA/usr/lib/python2.7/site-packages/ansible/modules/system/sysctl.pyt<module>s$


0#�	!

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