403Webshell
Server IP : 80.87.202.40  /  Your IP : 216.73.216.169
Web Server : Apache
System : Linux rospirotorg.ru 5.14.0-539.el9.x86_64 #1 SMP PREEMPT_DYNAMIC Thu Dec 5 22:26:13 UTC 2024 x86_64
User : bitrix ( 600)
PHP Version : 8.2.27
Disable Function : NONE
MySQL : OFF |  cURL : ON |  WGET : ON |  Perl : ON |  Python : OFF |  Sudo : ON |  Pkexec : ON
Directory :  /lib/python3.11/site-packages/ansible/modules/__pycache__/

Upload File :
current_dir [ Writeable] document_root [ Writeable]

 

Command :


[ Back ]     

Current File : /lib/python3.11/site-packages/ansible/modules/__pycache__/blockinfile.cpython-311.opt-1.pyc
�

���c+5���ddlmZmZmZeZdZdZddlZddl	Z	ddl
Z
ddlmZddl
mZddlmZmZd�Zd	�Zd
�Zedkre��dSdS)�)�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 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 in C(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.
    - 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 C(marker_begin) and C(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 C(state) were specified to C(absent).
    type: str
    default: ''
    aliases: [ content ]
  insertafter:
    description:
    - If specified and no begin/ending C(marker) lines are found, 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.
    - 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 C(marker) lines are found, 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.
    - 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 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:
  - 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:
    - 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
a�
# 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
  ansible.builtin.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/)
  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�dd��}|}|rad|vr|�	d|z���|�
||z��\}}	}
|dk}|dkr|�	d|�d	|
�����|r%|�|||jd
���dSdS)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.11/site-packages/ansible/modules/blockinfile.py�
write_changesr(�s4���%�&�-�8�8�8�N�E�7�
�	�%����A��G�G�H�����G�G�I�I�I��}� � ��T�2�2�H��L�E��?��x������!@�H�!M��N�N�N��+�+�H�w�,>�?�?���S�#��a���
��7�7�����57�R�R���">��
?�
?�
?��X����7�D��
�o�8V��W�W�W�W�W�X�X�c��|�|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�sb���1�1�&�-�@�@�I�
�.�.�y�%�d�.�K�K�B��	��w��G����A�A���G��r)c�t�tttddgd����tddddg���tdd	�
��tdddg�
��td���td���tdd�
��tdd�
��td���tdd�
��tdd�
�����ddggdd���}|j}|d}tj�|��r|�dd|z���tj�|��}|s�|�|d��s|�dd|z���tj�	|��}tj�|��s_|j
sX	tj|��nB#t$r5}|�d|�d|d�d |d!���"��Yd}~nd}~wwxYwd}g}nQt|d#��5}|���}ddd��n#1swxYwY|�d��}ddd$|zd$|zd%�}	|jr|r||	d&<|d}
|d}t#|d'��}t#|d(��}
|d)dk}|s|s|�dd*|z�+��|
�|�d,}|d-vr$t'jt#|d.�/����}n*|
d0vr$t'jt#|
d.�/����}nd}t'jt-d1��t-|d2��|
��t-tj��z}t'jt-d1��t-|d3��|
��t-tj��z}|rh|rf|�t-tj����s|t-tj��z
}|g|�d��z|gz}ng}dx}}t3|��D]\}}||kr|}||kr|}�d||fvr�d}|��|jt&jzr�|�|��}|rq|r7t;|���d4d|�����}ne|
r6t;|���d4d|� ����}n,t3|��D]\}}|�|��r|}�|�tC|��}n:|�|d!z
}n2|
�d}n-tC|��}n||krg|||d!z�<ng|||d!z�<|}|dkr_||d!z
�t-tj����s*||d!z
xxt-tj��z
cc<||||�<|rd5�"|��}nd5}|jr||	d6<||krd}d}n|�d7}d}n|sd8}d}nd9}d}d}|ro|j
sh|�|d:��r|r|�#|��}tj�$|d��}tK|||��|j
r|s|�|||	�;��i}tM||||��\}}d<|z|d=<d<|z|d><|	|g}|�|�|||�;��dS|�||||�?��dS)@NrT)�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_endrGrF)�
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: rz Error description: �r�rbz%s (content))�before�after�
before_header�after_headerrSrErDrCzFile %s not present)r.r�EOF)NrW�surrogate_or_strict)�errors)N�BOFz{mark}rJrK�
r)rTzFile createdz
Block removedzBlock insertedrI)r.rr+z%s (file attributes)rUrV)r.rr+�backup_file)'r�dictrrr�isdirr�exists�boolean�dirname�
check_mode�makedirs�	Exception�open�read�
splitlines�_diffr�	exit_json�re�compile�subr�linesep�endswith�	enumerate�flags�	MULTILINE�searchr	�count�end�start�len�join�backup_local�realpathr(r1)rrr�path_exists�destpath�e�original�linesr"r+rGrFrErDr:�insertre�marker0�marker1�
blocklines�n0�n1�i�line�match�resultrr.r\�	real_path�	attr_diff�difflists                               r'�mainr��sy��
���6�D�:V�:V�:V�W�W�W��E�9�x��>S�T�T�T��U�,L�M�M�M��E�2�	�{�C�C�C��%�(�(�(��5�)�)�)��V�U�3�3�3��V�U�3�3�3��u�%�%�%��5�'�:�:�:����6�6�6�
�
�
�,�]�;�<�!� �!���F�$�]�F��&�>�D�	�w�}�}�T���@����C�7�$�>�	�	@�	@�	@��'�.�.��&�&�K��*��~�~�f�X�.�/�/�	D�����!;�d�!B�
�
D�
D�
D��7�?�?�4�(�(���w�~�~�h�'�'�	x��0A�	x�
x���H�%�%�%�%���
x�
x�
x�� � � �ai�ai�ai�kl�mn�ko�ko�ko�qr�st�qu�qu�%v� �w�w�w�w�w�w�w�w�����
x���������
�$��
�
�	 ���v�v�x�x�H�	 �	 �	 �	 �	 �	 �	 �	 �	 �	 �	 ����	 �	 �	 �	 ��#�#�D�)�)����+�d�2�*�T�1�3�3�D�
�|�"��"�!��X���.�)�L���'�K��V�G�_�%�%�E�
�f�X�&�
'�
'�F��W�o��*�G��J�;�J�����,A�D�,H��I�I�I���� 3����-�'�'��:�h�{�;P�Q�Q�Q�R�R���	�]�	*�	*��:�h�|�<Q�R�R�R�S�S������f�Q�y�\�\�1�V�N�%;�#<�#<�f�E�E��"�*�
�
�U�G��f�Q�y�\�\�1�V�L�%9�#:�#:�F�C�C�a��
�m�m�S�G���5���~�~�a��
�m�m�,�,�	#��Q�r�z�]�]�"�E��Y��!1�!1�$�!7�!7�7�7�)�C�
�
��
��N�B���U�#�#�����4��7�?�?��B��7�?�?��B����B�x���
�����~���,�

� ����1�1���O�"�O�&�x�0�0�6�6�t�Q��	�	���L�L���%�O�&�x�0�0�6�6�t�Q����
�
�N�N���(��/�/���G�A�t����t�,�,������z���Z�Z����(��a����
�
%��B�B��U���B�B�	�b�����b��a��i�����b��a��i��
��
�A�v�v��R�!�V�}�%�%�a��
�m�m�4�4�	+��"�q�&�M�M�M�Q�r�z�]�]�*�M�M�M��E�"�R�%�L������%�������
�|����W�
��6��������	�	������
������������K��1�v�(�1��>�>�&��*�+�+�	4��	4� �-�-�d�3�3�K��G�$�$�V�F�^�4�4�	��f�f�i�0�0�0�
��>��>�����c���=�=�=��I�#�F�G�S�)�D�D�L�C��!7�$�!>�I�o�� 6�� =�I�n���i� �H�������c���A�A�A�A�A�����c��k��Z�Z�Z�Z�Zs*�=G�
H�+H�H�)I
�
I�I�__main__)�
__future__rrrr6�
__metaclass__�
DOCUMENTATION�EXAMPLESrjrr�ansible.module_utils.sixr�ansible.module_utils.basicr�ansible.module_utils._textrr	r(r1r��__name__�r)r'�<module>r�s���A�@�@�@�@�@�@�@�@�@��
�h�
�T:��x
�	�	�	�	�	�	�	�����&�&�&�&�&�&�4�4�4�4�4�4�:�:�:�:�:�:�:�:�X�X�X�*
�
�
�d[�d[�d[�N�z����D�F�F�F�F�F��r)

Youez - 2016 - github.com/yon3zu
LinuXploit