Anons79 Mini Shell

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

�
�Udac@`s�ddlmZmZmZeZidd6dgd6dd6ZdZd	Zdd
l	Z	dd
l
Z
dd
lZddlm
Z
ddlmZdd
lmZd�Zd�Zd�Zedkr�e�nd
S(i(tabsolute_importtdivisiontprint_functions1.1tmetadata_versiontpreviewtstatustcoretsupported_bys�
---
module: blockinfile
short_description: Insert/update/remove a text block surrounded by marker lines
version_added: '2.0'
description:
- This module will insert/update/remove a block of multi-line text surrounded by customizable marker lines.
author:
- Yaegashi Takeshi (@yaegashi)
options:
  path:
    description:
    - The file to modify.
    - Before Ansible 2.3 this option was only usable as I(dest), I(destfile) and I(name).
    type: path
    required: yes
    aliases: [ dest, destfile, name ]
  state:
    description:
    - Whether the block should be there or not.
    type: str
    choices: [ absent, present ]
    default: present
  marker:
    description:
    - The marker line template.
    - C({mark}) will be replaced with the values C(in marker_begin) (default="BEGIN") and C(marker_end) (default="END").
    - Using a custom marker without the C({mark}) variable may result in the block being repeatedly inserted on subsequent playbook runs.
    type: str
    default: '# {mark} ANSIBLE MANAGED BLOCK'
  block:
    description:
    - The text to insert inside the marker lines.
    - If it is missing or an empty string, the block will be removed as if C(state) were specified to C(absent).
    type: str
    default: ''
    aliases: [ content ]
  insertafter:
    description:
    - If specified, the block will be inserted after the last match of specified regular expression.
    - A special value is available; C(EOF) for inserting the block at the end of the file.
    - If specified regular expression has no matches, C(EOF) will be used instead.
    type: str
    choices: [ EOF, '*regex*' ]
    default: EOF
  insertbefore:
    description:
    - If specified, the block will be inserted before the last match of specified regular expression.
    - A special value is available; C(BOF) for inserting the block at the beginning of the file.
    - If specified regular expression has no matches, the block will be inserted at the end of the file.
    type: str
    choices: [ BOF, '*regex*' ]
  create:
    description:
    - Create a new file if it does not exist.
    type: bool
    default: no
  backup:
    description:
    - Create a backup file including the timestamp information so you can
      get the original file back if you somehow clobbered it incorrectly.
    type: bool
    default: no
  marker_begin:
    description:
    - This will be inserted at C({mark}) in the opening ansible block marker.
    type: str
    default: BEGIN
    version_added: '2.5'
  marker_end:
    required: false
    description:
    - This will be inserted at C({mark}) in the closing ansible block marker.
    type: str
    default: END
    version_added: '2.5'
notes:
  - This module supports check mode.
  - When using 'with_*' loops be aware that if you do not set a unique mark the block will be overwritten on each iteration.
  - As of Ansible 2.3, the I(dest) option has been changed to I(path) as default, but I(dest) still works as well.
  - Option I(follow) has been removed in Ansible 2.5, because this module modifies the contents of the file so I(follow=no) doesn't make sense.
  - When more then one block should be handled in one file you must change the I(marker) per task.
extends_documentation_fragment:
- files
- validate
sE
# Before Ansible 2.3, option 'dest' or 'name' was used instead of 'path'
- name: Insert/Update "Match User" configuration block in /etc/ssh/sshd_config
  blockinfile:
    path: /etc/ssh/sshd_config
    block: |
      Match User ansible-agent
      PasswordAuthentication no

- name: Insert/Update eth0 configuration stanza in /etc/network/interfaces
        (it might be better to copy files into /etc/network/interfaces.d/)
  blockinfile:
    path: /etc/network/interfaces
    block: |
      iface eth0 inet static
          address 192.0.2.23
          netmask 255.255.255.0

- name: Insert/Update configuration using a local file and validate it
  blockinfile:
    block: "{{ lookup('file', './local/sshd_config') }}"
    dest: /etc/ssh/sshd_config
    backup: yes
    validate: /usr/sbin/sshd -T -f %s

- name: Insert/Update HTML surrounded by custom markers after <body> line
  blockinfile:
    path: /var/www/html/index.html
    marker: "<!-- {mark} ANSIBLE MANAGED BLOCK -->"
    insertafter: "<body>"
    block: |
      <h1>Welcome to {{ ansible_hostname }}</h1>
      <p>Last updated on {{ ansible_date_time.iso8601 }}</p>

- name: Remove HTML as well as surrounding markers
  blockinfile:
    path: /var/www/html/index.html
    marker: "<!-- {mark} ANSIBLE MANAGED BLOCK -->"
    block: ""

- name: Add mappings to /etc/hosts
  blockinfile:
    path: /etc/hosts
    block: |
      {{ item.ip }} {{ item.name }}
    marker: "# {mark} ANSIBLE MANAGED BLOCK {{ item.name }}"
  loop:
    - { name: host1, ip: 10.10.1.10 }
    - { name: host2, ip: 10.10.1.11 }
    - { name: host3, ip: 10.10.1.12 }
N(tb(t
AnsibleModule(tto_bytescC`stjd|j�\}}tj|d�}|j|�|j�|jjdd�}|}|r�d|kr�|j
dd|�n|j||�\}}	}
|dk}|dkr�|j
dd||
f�q�n|r|j||d	|jd	�ndS(
Ntdirtwbtvalidates%stmsgsvalidate must contain %%s: %sis"failed to validate: rc:%s error:%st
unsafe_writes(
ttempfiletmkstempttmpdirtostfdopentwritetclosetparamstgettNonet	fail_jsontrun_commandtatomic_move(tmoduletcontentstpathttmpfdttmpfiletfR
tvalidtrctoutterr((sE/usr/lib/python2.7/site-packages/ansible/modules/files/blockinfile.pyt
write_changes�s 

cC`sZ|j|j�}|j|td|�rP|r=|d7}nt}|d7}n||fS(Ntdiffs and s,ownership, perms or SE linux context changed(tload_file_common_argumentsRt set_file_attributes_if_differenttFalsetTrue(RtchangedtmessageR(t	file_args((sE/usr/lib/python2.7/site-packages/ansible/modules/files/blockinfile.pytcheck_file_attrs�s

cC`sItdtdtdddtddddg�d	tdd
ddd
ddg�dtdd
dd�dtdd
ddddg�dtdd
�dtdd
�dtdddt�dtdddt�dtdd
�dtdd
dd�dtdd
dd��dddggdtd t�}|j}|d}tjj|�rh|jd!d"d#d$|�ntjj	|�}|s=|j
|d�s�|jd!d%d#d&|�ntjj|�}tjj	|�r.|jr.ytj
|�Wq.tk
r*}|jd#d'||d(|d)f�q.Xnd}g}n1t|d*�}|j�}|j�|j�}idd+6dd,6d-|d.6d-|d/6}	|jr�|r�||	d+<n|d}
|d}t|d�}t|d�}
|d	dk}|r#|r#|jd0td#d1|�n|
dkrD|dkrDd2}n|d>krntjt|d3d4��}n0|
d?kr�tjt|
d3d4��}nd}tjtd6�t|d�|
�}tjtd6�t|d�|
�}|r;|r;|jjd7�rtjd|d�}n|g|j�|g}ng}d}}xDt|�D]6\}}||kry|}n||krX|}qXqXWd||fkrFd}|dk	r"x2t|�D]$\}}|j|�r�|}q�q�W|dkrt|�}qC|dk	rC|d)7}qCq}|
dk	r7d(}q}t|�}n7||krfg|||d)+ng|||d)+|}||||+|r�td8�j |�}|dks�|j!td8��r�|td8�7}q�nd}|jr�||	d,<n||krd}t}n<|dkr.d9}t}n!|sCd:}t}nd;}t}|r�|jr�|j
|d�r�|r�|j"|�ntjj#|d�}t$|||�n|jr�|r�|jd0|d#|d<|	�ni}t%||||�\}}d=||d.<d=||d/<|	|g}|jd0|d#|d<|�dS(@Nt
argument_specRttypetrequiredtaliasestdesttdestfiletnametstatetstrtdefaulttpresenttchoicestabsenttmarkers# {mark} ANSIBLE MANAGED BLOCKtblockttcontenttinsertaftertinsertbeforetcreatetbooltbackupR
tmarker_begintBEGINt
marker_endtENDtmutually_exclusivetadd_file_common_argstsupports_check_modeR$iRsPath %s is a directory !isPath %s does not exist !s6Error creating %s Error code: %s Error description: %siitrbtbeforetafters%s (content)t
before_headertafter_headerR-sFile %s not presenttEOFterrorstsurrogate_or_stricttBOFs{mark}s1.s
sFile createds
Block removedsBlock insertedR(s%s (file attributes)(NRS(NRV(&R	tdictR,R+RRRtisdirRtexiststbooleantdirnamet
check_modetmakedirst	ExceptionRtopentreadRt
splitlinest_diffR
t	exit_jsontretcompiletsubRtansible_versiont
startswitht	enumeratetsearchtlentjointendswithtbackup_localtrealpathR'R0(RRRtpath_existstdestpathtetoriginaltlinesR"R(RCRBR?R>R;tinsertretmarker0tmarker1t
blocklinestn0tn1titlinetresultRR-t	real_patht	attr_difftdifflist((sE/usr/lib/python2.7/site-packages/ansible/modules/files/blockinfile.pytmain�s�$!		
,	




	%%
	

	
!	
			t__main__(t
__future__RRRR2t
__metaclass__tANSIBLE_METADATAt
DOCUMENTATIONtEXAMPLESRdRRtansible.module_utils.sixRtansible.module_utils.basicR	tansible.module_utils._textR
R'R0R�t__name__(((sE/usr/lib/python2.7/site-packages/ansible/modules/files/blockinfile.pyt<module>s"


W4		
	�

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