Anons79 Mini Shell

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

�
�Udac@`s�ddlmZmZmZeZidd6dgd6dd6ZdZd	Zdd
l	Z	dd
l
Z
dd
lZddlm
Z
mZddlmZd
�Zd�Zd�Zedkr�e�nd
S(i(tabsolute_importtdivisiontprint_functions1.1tmetadata_versiontstableinterfacetstatust	communitytsupported_bys�
---
module: replace
author: Evan Kaufman (@EvanK)
extends_documentation_fragment:
    - files
    - validate
short_description: Replace all instances of a particular string in a
                   file using a back-referenced regular expression
description:
  - This module will replace all instances of a pattern within a file.
  - It is up to the user to maintain idempotence by ensuring that the
    same pattern would never match any replacements made.
version_added: "1.6"
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: true
    aliases: [ dest, destfile, name ]
  regexp:
    description:
      - The regular expression to look for in the contents of the file.
      - Uses Python regular expressions; see
        U(http://docs.python.org/2/library/re.html).
      - Uses MULTILINE mode, which means C(^) and C($) match the beginning
        and end of the file, as well as the beginning and end respectively
        of I(each line) of the file.
      - Does not use DOTALL, which means the C(.) special character matches
        any character I(except newlines). A common mistake is to assume that
        a negated character set like C([^#]) will also not match newlines.
      - In order to exclude newlines, they must be added to the set like C([^#\n]).
      - Note that, as of Ansible 2.0, short form tasks should have any escape
        sequences backslash-escaped in order to prevent them being parsed
        as string literal escapes. See the examples.
    type: str
    required: true
  replace:
    description:
      - The string to replace regexp matches.
      - May contain backreferences that will get expanded with the regexp capture groups if the regexp matches.
      - If not set, matches are removed entirely.
      - Backreferences can be used ambiguously like C(\1), or explicitly like C(\g<1>).
    type: str
  after:
    description:
      - If specified, only content after this match will be replaced/removed.
      - Can be used in combination with C(before).
      - Uses Python regular expressions; see
        U(http://docs.python.org/2/library/re.html).
      - Uses DOTALL, which means the C(.) special character I(can match newlines).
    type: str
    version_added: "2.4"
  before:
    description:
      - If specified, only content before this match will be replaced/removed.
      - Can be used in combination with C(after).
      - Uses Python regular expressions; see
        U(http://docs.python.org/2/library/re.html).
      - Uses DOTALL, which means the C(.) special character I(can match newlines).
    type: str
    version_added: "2.4"
  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
  others:
    description:
      - All arguments accepted by the M(file) module also work here.
    type: str
  encoding:
    description:
      - The character encoding for reading and writing the file.
    type: str
    default: utf-8
    version_added: "2.4"
notes:
  - As of Ansible 2.3, the I(dest) option has been changed to I(path) as default, but I(dest) still works as well.
  - As of Ansible 2.7.10, the combined use of I(before) and I(after) works properly. If you were relying on the
    previous incorrect behavior, you may be need to adjust your tasks.
    See U(https://github.com/ansible/ansible/issues/31354) for details.
  - 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.
sE
- name: Before Ansible 2.3, option 'dest', 'destfile' or 'name' was used instead of 'path'
  replace:
    path: /etc/hosts
    regexp: '(\s+)old\.host\.name(\s+.*)?$'
    replace: '\1new.host.name\2'

- name: Replace after the expression till the end of the file (requires Ansible >= 2.4)
  replace:
    path: /etc/apache2/sites-available/default.conf
    after: 'NameVirtualHost [*]'
    regexp: '^(.+)$'
    replace: '# \1'

- name: Replace before the expression till the begin of the file (requires Ansible >= 2.4)
  replace:
    path: /etc/apache2/sites-available/default.conf
    before: '# live site config'
    regexp: '^(.+)$'
    replace: '# \1'

# Prior to Ansible 2.7.10, using before and after in combination did the opposite of what was intended.
# see https://github.com/ansible/ansible/issues/31354 for details.
- name: Replace between the expressions (requires Ansible >= 2.4)
  replace:
    path: /etc/hosts
    after: '<VirtualHost [*]>'
    before: '</VirtualHost>'
    regexp: '^(.+)$'
    replace: '# \1'

- name: Supports common file attributes
  replace:
    path: /home/jdoe/.ssh/known_hosts
    regexp: '^old\.host\.name[^\n]*\n'
    owner: jdoe
    group: jdoe
    mode: '0644'

- name: Supports a validate command
  replace:
    path: /etc/apache/ports
    regexp: '^(NameVirtualHost|Listen)\s+80\s*$'
    replace: '\1 127.0.0.1:8080'
    validate: '/usr/sbin/apache2ctl -f %s -t'

- name: Short form task (in ansible 2+) necessitates backslash-escaped sequences
  replace: path=/etc/hosts regexp='\\b(localhost)(\\d*)\\b' replace='\\1\\2.localdomain\\2 \\1\\2'

- name: Long form task does not
  replace:
    path: /etc/hosts
    regexp: '\b(localhost)(\d*)\b'
    replace: '\1\2.localdomain\2 \1\2'

- name: Explicitly specifying positional matched groups in replacement
  replace:
    path: /etc/ssh/sshd_config
    regexp: '^(ListenAddress[ ]+)[^\n]+$'
    replace: '\g<1>0.0.0.0'

- name: Explicitly specifying named matched groups
  replace:
    path: /etc/ssh/sshd_config
    regexp: '^(?P<dctv>ListenAddress[ ]+)(?P<host>[^\n]+)$'
    replace: '#\g<dctv>\g<host>\n\g<dctv>0.0.0.0'
N(tto_texttto_bytes(t
AnsibleModulecC`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((sA/usr/lib/python2.7/site-packages/ansible/modules/files/replace.pyt
write_changes�s 

cC`sT|j|j�}|j|t�rJ|r7|d7}nt}|d7}n||fS(Ns and s,ownership, perms or SE linux context changed(tload_file_common_argumentsRt set_file_attributes_if_differenttFalsetTrue(Rtchangedtmessaget	file_args((sA/usr/lib/python2.7/site-packages/ansible/modules/files/replace.pytcheck_file_attrs�s

cC`s�tdtdtdddtddddg�d	tdd
dt�dtdd
dd
�dtdd
�dtdd
�dtdddt�dtdd
�dtdd
dd��dtdt�}|j}|d}|d}t�}t|ddddd�|d<t|ddddd�|d<t|d	dddd�|d	<t|ddddd�|d<tjj|�r�|j	dddd|�ntjj
|�s�|j	dddd |�n7t|d!�}t|j�ddd|�}|j
�d"}|dr3|dr3d#|d|df}n6|drNd$|d}n|drid%|d}n|r�tj|tj�}tj||�}	|	r�|	jd&�}
|	jd&�|	jd&�g}q�d'||d<t|d(<|j|�n|}
tj|d	tj�}tj||d|
d)�}
|
d*d)kr�|
|
d)kr�|r�||d) |
d)||d*|
d*f}
nd+|
d*}t}|jr�i|d,6|d6|d-6|
d)d6|d.<q�nd
}t}|rT|jrT|drtjj
|�r|j|�|d/<ntjj|�}t|t|
d)d|�|�nt|||�\|d<|d(<|j|�dS(0Nt
argument_specRttypetrequiredtaliasestdesttdestfiletnametregexptstrtreplacetdefaultttaftertbeforetbackuptboolR
tencodingsutf-8tadd_file_common_argstsupports_check_modeterrorstsurrogate_or_strictt	nonstringtpassthruR$iRsPath %s is a directory !isPath %s does not exist !trbuu%s(?P<subsection>.*?)%su%s(?P<subsection>.*)u(?P<subsection>.*)%st
subsections@Pattern for before/after params did not match the given file: %sR,iis%s replacements madet
before_headertafter_headertdifftbackup_file(R
tdictR+R*RRRRtisdirRtexiststopentreadRtretcompiletDOTALLtsearchtgrouptstarttendt	exit_jsont	MULTILINEtsubnt_difft
check_modetbackup_localtrealpathR'R	R/(RRRR@tres_argsR"Rtpatternt
section_retmatchtsectiontindicestmretresultRR,((sA/usr/lib/python2.7/site-packages/ansible/modules/files/replace.pytmain�s�$		

	    


!
 /	# t__main__(t
__future__RRRR1t
__metaclass__tANSIBLE_METADATAt
DOCUMENTATIONtEXAMPLESRRRRtansible.module_utils._textRR	tansible.module_utils.basicR
R'R/Rht__name__(((sA/usr/lib/python2.7/site-packages/ansible/modules/files/replace.pyt<module>s 


YD		
	W

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