HEX
Server: Apache
System: Linux server2.voipitup.com.au 4.18.0-553.104.1.lve.el8.x86_64 #1 SMP Tue Feb 10 20:07:30 UTC 2026 x86_64
User: posscale (1027)
PHP: 8.2.29
Disabled: exec,passthru,shell_exec,system
Upload Files
File: //opt/saltstack/salt/lib/python3.10/site-packages/salt/modules/__pycache__/puppet.cpython-310.pyc
o

�N�g+�@s�dZddlZddlZddlZddlZddlZddlZddlZddl	Zddl
ZddlmZe�
e�Zdd�Zdd�ZGdd	�d	�Zd
d�Zdd
�Zdd�Zddd�Zdd�Zdd�Zdd�Zddd�Zddd�ZdS)z
Execute puppet routines
�N)�CommandExecutionErrorcCs*d�dd�dD��}|rdd�|�fSdS)z*
    Only load if puppet is installed
    z, css&�|]}tjj�|�dur|VqdS�N)�salt�utils�path�which)�.0Zexe�r	�G/opt/saltstack/salt/lib/python3.10/site-packages/salt/modules/puppet.py�	<genexpr>s��z__virtual__.<locals>.<genexpr>)Zfacter�puppetFz=The puppet execution module cannot be loaded: {} unavailable.r)�join�format)Zunavailable_exesr	r	r
�__virtual__s
���rcCsDz|�dd�\}}|��}W||fSty!d}d}Y||fSw)Nz => �)�split�strip�
ValueError)�output�fact�valuer	r	r
�_format_fact&s
��rc@s*eZdZdZdd�Zdd�Zd	dd�ZdS)
�_PuppetzD
    Puppet helper class. Used to format command for execution.
    cCs�d|_g|_ddi|_g|_tdd�}tjj�|�}|d|_	|d|_
|d|_|j	d	|_|j	d
|_
|j
d|_|j	d|_d
S)z�
        Setup a puppet instance, based on the premis that default usage is to
        run 'puppet agent --test'. Configuration and run states are stored in
        the default locations.
        �agentZcolor�false�cmd.runz:puppet config print --render-as yaml vardir rundir confdir�vardir�rundir�confdirz/state/agent_disabled.lockz/state/agent_catalog_run.lockz
/agent.pidz/state/last_run_summary.yamlN)�subcmd�subcmd_args�kwargs�args�__salt__rr�yaml�	safe_loadrrr�disabled_lockfile�run_lockfile�
agent_pidfile�lastrunfile)�selfZ
puppet_configZconfr	r	r
�__init__5s
�


z_Puppet.__init__cCs�djdi|j��}d�|j�}|d�dd�|jD��7}|d�dd�|j��D��7}tjj	�
�r7d�||�Sd|�d|�d	�S)zJ
        Format the command string to executed using cmd.run_all.
        z5puppet {subcmd} --vardir {vardir} --confdir {confdir}� �cSsg|]}d|���qS)� --r	)r�kr	r	r
�
<listcomp>Wsz$_Puppet.__repr__.<locals>.<listcomp>cSs g|]\}}d|�d|���qS)r.r,r	)rr/�vr	r	r
r0Xs zCcmd /V:ON /c {} {} ^& if !ERRORLEVEL! EQU 2 (EXIT 0) ELSE (EXIT /B)�(z) || test $? -eq 2Nr	)r�__dict__r
r r"r!�itemsrr�platformZ
is_windows)r*�cmdr"r	r	r
�__repr__Ns��z_Puppet.__repr__NcCsL|rt|�pg}|jdkr|dg|_|d=|jdkr!|�dg�||_dS)z�
        Read in arguments for the current subcommand. These are added to the
        cmd line without '--' appended. Any others are redirected as standard
        options with the double hyphen prefixed.
        �applyrr�testN)�listrr �extendr")r*r"r	r	r
�	argumentsas


z_Puppet.argumentsr)�__name__�
__module__�__qualname__�__doc__r+r7r<r	r	r	r
r0s
rcOslt�}d}|D]}|dvr||_q||f7}q|�|�|j�tjjjdi|���t	dt
|�dd�}|S)a=
    Execute a puppet run and return a dict with the stderr, stdout,
    return code, etc. The first positional argument given is checked as a
    subcommand. Following positional arguments should be ordered with arguments
    required by the subcommand first, followed by non-keyword arguments.
    Tags are specified by a tag keyword and comma separated list of values. --
    http://docs.puppetlabs.com/puppet/latest/reference/lang_tags.html

    CLI Examples:

    .. code-block:: bash

        salt '*' puppet.run
        salt '*' puppet.run tags=basefiles::edit,apache::server
        salt '*' puppet.run agent onetime no-daemonize no-usecacheonfailure no-splay ignorecache
        salt '*' puppet.run debug
        salt '*' puppet.run apply /a/b/manifest.pp modulepath=/a/b/modules tags=basefiles::edit,apache::server
    r	)rr8�cmd.run_allT�Zpython_shell)rrr<r!�updaterrr"Zclean_kwargsr#�repr)r"r!rZ	buildargs�arg�retr	r	r
�runxs
rGcOs|d7}t|i|��S)a�
    Execute a puppet noop run and return a dict with the stderr, stdout,
    return code, etc. Usage is the same as for puppet.run.

    CLI Example:

    .. code-block:: bash

        salt '*' puppet.noop
        salt '*' puppet.noop tags=basefiles::edit,apache::server
        salt '*' puppet.noop debug
        salt '*' puppet.noop apply /a/b/manifest.pp modulepath=/a/b/modules tags=basefiles::edit,apache::server
    )�noop)rG)r"r!r	r	r
rH�srHc
Cs`t�}tj�|j�r.z	t�|j�WdSty-}zd|��}t�|�t	|��d}~wwdS)z�
    .. versionadded:: 2014.7.0

    Enable the puppet agent

    CLI Example:

    .. code-block:: bash

        salt '*' puppet.enable
    zFailed to enable: NTF)
r�osr�isfiler&�remove�OSError�log�errorr)r�exc�msgr	r	r
�enable�s�

��rQcCs�t�}tj�|j�rdStjj�|jd��?}z#|dur!d|�d�nd}|�	tjj
�|��|��WWd�dSt
yS}zd|��}t�|�t|��d}~ww1sWwYdS)	a2
    .. versionadded:: 2014.7.0

    Disable the puppet agent

    message
        .. versionadded:: 2015.5.2

        Disable message to send to puppet

    CLI Example:

    .. code-block:: bash

        salt '*' puppet.disable
        salt '*' puppet.disable 'Disabled, contact XYZ before enabling'
    F�wNz{"disabled_message":"z"}z{}TzFailed to disable: )rrIrrJr&rr�files�fopen�write�stringutilsZto_str�closerLrMrNr)�messagerZlockfilerPrOr	r	r
�disable�s(���

���rYc	Cs(t�}tj�|j�rdStj�|j�rOz/tjj�	|jd��}t
tjj�|�
���}t�|d�Wd�WdS1s;wYWdSttfyNYdSwtj�|j�r�z/tjj�	|jd��}t
tjj�|�
���}t�|d�Wd�WdS1s~wYWdSttfy�YdSwd	S)
z�
    .. versionadded:: 2014.7.0

    Display puppet agent status

    CLI Example:

    .. code-block:: bash

        salt '*' puppet.status
    zAdministratively disabled�rrNzStale lockfilezApplying a catalogz
Stale pidfilezIdle daemonZStopped)rrIrrJr&r'rrrSrT�intrVZ
to_unicode�read�killrLrr()r�fp_�pidr	r	r
�status�s8��������r`c
Cs<t�}zrtjj�|jd��}tjj�|�}Wd�n1swYi}d|vrfztj�	t
|dd����|d<Wntt
tfyLd|d<Ynwi|d<dD]}||dvre|d||d|<qSd|vrs|d|d<W|SW|Stjjjy�}ztd|����d}~wty�}ztd	|����d}~ww)
z�
    .. versionadded:: 2014.7.0

    Show a summary of the last puppet agent run

    CLI Example:

    .. code-block:: bash

        salt '*' puppet.summary
    rZN�timeZlast_runzinvalid or missing timestamp)�totalZconfig_retrievalZ	resourcesz'YAML error parsing puppet run summary: z#Unable to read puppet run summary: )rrrrSrTr)r$r%�datetime�
fromtimestampr[�	isoformat�	TypeErrorr�KeyErrorZ	YAMLErrorrrL)rr^�report�result�keyrOr	r	r
�summarysB
��
��������rkcCstdd�}|s
dS|S)z�
    Runs a plugin sync between the puppet master and agent

    CLI Example:

    .. code-block:: bash

        salt '*' puppet.plugin_sync
    rzpuppet plugin downloadr-)r#)rFr	r	r
�plugin_syncIs
rlFcCsti}|rdnd}tdd|���}|ddkrt|d��|d}|��D]}|s*q%t|�\}}|s3q%|||<q%|S)	zv
    Run facter and return the results

    CLI Example:

    .. code-block:: bash

        salt '*' puppet.facts
    �--puppetr-rA�facter �retcoder�stderr�stdout)r#r�
splitlinesr)rrF�
opt_puppetZcmd_retr�linerrr	r	r
�factsZs

rucCsT|rdnd}tdd|�d|��dd�}|dd	kr t|d
��|ds&dS|dS)zy
    Run facter for a specific fact

    CLI Example:

    .. code-block:: bash

        salt '*' puppet.fact kernel
    rmr-rArnr,FrBrorrprq)r#r)�namerrsrFr	r	r
rzs
rr)F)r@rc�loggingrIZsalt.utils.argsrZsalt.utils.filesZsalt.utils.pathZsalt.utils.platformZsalt.utils.stringutilsZsalt.utils.yamlZsalt.exceptionsr�	getLoggerr=rMrrrrGrHrQrYr`rkrlrurr	r	r	r
�<module>s0

H(
)(,