HEX
Server: Apache
System: Linux server2.voipitup.com.au 4.18.0-553.109.1.lve.el8.x86_64 #1 SMP Thu Mar 5 20:23:46 UTC 2026 x86_64
User: posscale (1027)
PHP: 8.2.30
Disabled: exec,passthru,shell_exec,system
Upload Files
File: //opt/saltstack/salt/lib/python3.10/site-packages/salt/states/__pycache__/augeas.cpython-310.pyc
o

�N�g-*�@sxdZddlZddlZddlZddlZddlZddlZddl	Zddl
mZe�e
�Zdd�Zdd�Zdd	�Zdd
d�ZdS)
at
Configuration management using Augeas

.. versionadded:: 0.17.0

This state requires the ``augeas`` Python module.

.. _Augeas: http://augeas.net/

Augeas_ can be used to manage configuration files.

.. warning::

    Minimal installations of Debian and Ubuntu have been seen to have packaging
    bugs with python-augeas, causing the augeas module to fail to import. If
    the minion has the augeas module installed, and the state fails with a
    comment saying that the state is unavailable, first restart the salt-minion
    service. If the problem persists past that, the following command can be
    run from the master to determine what is causing the import to fail:

    .. code-block:: bash

        salt minion-id cmd.run 'python -c "from augeas import Augeas"'

    For affected Debian/Ubuntu hosts, installing ``libpython2.7`` has been
    known to resolve the issue.

�N)�
METHOD_MAPcCsdtvrdSdS)N�augeas.executeZaugeas)Fz!augeas module could not be loaded)�__salt__�rr�F/opt/saltstack/salt/lib/python3.10/site-packages/salt/states/augeas.py�__virtual__+srcCs4tj�|�s
|dkr|dkrd}|Sttj�|��S)zA
    Recursively workout the file name from an augeas change
    �/N)�os�path�isfile�_workout_filename�dirname)�filenamerrrr1s
rcCs d}|D]�}zZ|�dd�\}}|tvrd|�d�}t|��t|}tjj�|�}|dvr1|d}n|\}	}	}|�d�sDd	�|�}t|��t	�
d
d|�}|dur]||kr]d�||�}t|��|}Wqttfy�}
zt�
|
�d
t�vr}d�|�}t|��t|
�}t|��d}
~
wwt|�}|S)z�
    Ensure all changes are fully qualified and affect only one file.
    This ensures that the diff output works and a state change is not
    incorrectly reported.
    N� �zCommand z is not supported (yet))�setZsetm�move�removerz/fileszLChanges should be prefixed with /files if no context is provided, change: {}�
^/files|/$�zKChanges should be made to one file at a time, detected changes to {} and {}�errorz8Invalid formatted command, see debug log for details: {})�splitr�
ValueError�salt�utils�argsZshlex_split�
startswith�format�re�sub�
IndexError�logr�locals�strr)�changesrZchange_�cmd�argr�method�partsZ	filename_�_�errrrr�_check_filepath=sN


��

�����r+c
KsJ|ddid�}|rt|t�sd|d<|S|dur(t|t�s#d|d<|Sd�|�}d}|durPzt|�}Wn"tyO}zd	|��|d<|WYd}~Sd}~wwt�d
d|�}tdr~d|d
<d|d<|rq|dd|�d�7<|dd�|�7<|Sg}	|dur�tj	�
|�r�tjj
�|d��}
dd�|
��D�}	Wd�n1s�wYtd||||d�}|d|d
<|d
dur�d�|d�|d<|S|du�rtj	�
|��rtjj
�|d��}
dd�|
��D�}d�tj|	|dd��}
Wd�n1s�wY|
�rd|d<d|
i|d<|Sd |d<|Sd|d<d!|i|d<|S)"aS
    .. versionadded:: 2014.7.0

    This state replaces :py:func:`~salt.states.augeas.setvalue`.

    Issue changes to Augeas, optionally for a specific context, with a
    specific lens.

    name
        State name

    context
        A file path, prefixed by ``/files``. Should resolve to an actual file
        (not an arbitrary augeas path). This is used to avoid duplicating the
        file name for each item in the changes list (for example, ``set bind 0.0.0.0``
        in the example below operates on the file specified by ``context``). If
        ``context`` is not specified, a file path prefixed by ``/files`` should be
        included with the ``set`` command.

        The file path is examined to determine if the
        specified changes are already present.

        .. code-block:: yaml

            redis-conf:
              augeas.change:
                - context: /files/etc/redis/redis.conf
                - changes:
                  - set bind 0.0.0.0
                  - set maxmemory 1G

    changes
        List of changes that are issued to Augeas. Available commands are
        ``set``, ``setm``, ``mv``/``move``, ``ins``/``insert``, and
        ``rm``/``remove``.

    lens
        The lens to use, needs to be suffixed with `.lns`, e.g.: `Nginx.lns`.
        See the `list of stock lenses <http://augeas.net/stock_lenses.html>`_
        shipped with Augeas.

    .. versionadded:: 2016.3.0

    load_path
        A list of directories that modules should be searched in. This is in
        addition to the standard load path and the directories in
        AUGEAS_LENS_LIB.


    Usage examples:

    Set the ``bind`` parameter in ``/etc/redis/redis.conf``:

    .. code-block:: yaml

        redis-conf:
          augeas.change:
            - changes:
              - set /files/etc/redis/redis.conf/bind 0.0.0.0

    .. note::

        Use the ``context`` parameter to specify the file you want to
        manipulate. This way you don't have to include this in the changes
        every time:

        .. code-block:: yaml

            redis-conf:
              augeas.change:
                - context: /files/etc/redis/redis.conf
                - changes:
                  - set bind 0.0.0.0
                  - set databases 4
                  - set maxmemory 1G

    Augeas is aware of a lot of common configuration files and their syntax.
    It knows the difference between for example ini and yaml files, but also
    files with very specific syntax, like the hosts file. This is done with
    *lenses*, which provide mappings between the Augeas tree and the file.

    There are many `preconfigured lenses`_ that come with Augeas by default,
    and they specify the common locations for configuration files. So most
    of the time Augeas will know how to manipulate a file. In the event that
    you need to manipulate a file that Augeas doesn't know about, you can
    specify the lens to use like this:

    .. code-block:: yaml

        redis-conf:
          augeas.change:
            - lens: redis.lns
            - context: /files/etc/redis/redis.conf
            - changes:
              - set bind 0.0.0.0

    .. note::

        Even though Augeas knows that ``/etc/redis/redis.conf`` is a Redis
        configuration file and knows how to parse it, it is recommended to
        specify the lens anyway. This is because by default, Augeas loads all
        known lenses and their associated file paths. All these files are
        parsed when Augeas is loaded, which can take some time. When specifying
        a lens, Augeas is loaded with only that lens, which speeds things up
        quite a bit.

    .. _preconfigured lenses: http://augeas.net/stock_lenses.html

    A more complex example, this adds an entry to the services file for Zabbix,
    and removes an obsolete service:

    .. code-block:: yaml

        zabbix-service:
          augeas.change:
            - lens: services.lns
            - context: /files/etc/services
            - changes:
              - ins service-name after service-name[last()]
              - set service-name[last()] "zabbix-agent"
              - set "service-name[. = 'zabbix-agent']/port" 10050
              - set "service-name[. = 'zabbix-agent']/protocol" tcp
              - set "service-name[. = 'zabbix-agent']/#comment" "Zabbix Agent service"
              - rm "service-name[. = 'im-obsolete']"
            - unless: grep "zabbix-agent" /etc/services

    .. warning::

        Don't forget the ``unless`` here, otherwise it will fail on next runs
        because the service is already defined. Additionally you have to quote
        lines containing ``service-name[. = 'zabbix-agent']`` otherwise
        :mod:`augeas_cfg <salt.modules.augeas_cfg>` execute will fail because
        it will receive more parameters than expected.

    .. note::

        Order is important when defining a service with Augeas, in this case
        it's ``port``, ``protocol`` and ``#comment``. For more info about
        the lens check `services lens documentation`_.

    .. _services lens documentation:

    http://augeas.net/docs/references/lenses/files/services-aug.html#Services.record

    Fr)�name�result�commentr$z%'changes' must be specified as a listr.Nz''load_path' must be specified as a list�:zError: r�testTr-zExecuting commandsz
 in file "z":
�
�rcS�g|]	}tjj�|��qSr�rrZstringutilsZ
to_unicode��.0�xrrr�
<listcomp>'�zchange.<locals>.<listcomp>r)�context�lensZcommands�	load_path�retvalz	Error: {}rcSr3rr4r5rrrr84r9r)�nzChanges have been saved�diffr$zNo changes madeZupdates)�
isinstance�list�joinr+rrrZ__opts__r	r
rrr�filesZfopen�	readlinesrr�difflibZunified_diff)r,r:r$r;r<�kwargs�retrr*Zold_fileZfile_r-Znew_filer?rrr�changessj

�������rH)NNNN)�__doc__rE�loggingZos.pathr	rZsalt.utils.argsrZsalt.utils.filesZsalt.utils.stringutilsZsalt.modules.augeas_cfgr�	getLogger�__name__r!rrr+rHrrrr�<module>s
6