HEX
Server: Apache/2.4.65 (Debian)
System: Linux kubikelcreative 5.10.0-35-amd64 #1 SMP Debian 5.10.237-1 (2025-05-19) x86_64
User: www-data (33)
PHP: 8.4.13
Disabled: NONE
Upload Files
File: //usr/lib/python3/dist-packages/cloudinit/config/__pycache__/cc_puppet.cpython-39.pyc
a

��`o#�@s�dZddlZddlZddlZddlmZddlmZddlmZddlm	Z	dZ
dZd	Zd
Z
Gdd�de�Zd
d�Zdd�ZdS)a_
Puppet
------
**Summary:** install, configure and start puppet

This module handles puppet installation and configuration. If the ``puppet``
key does not exist in global configuration, no action will be taken. If a
config entry for ``puppet`` is present, then by default the latest version of
puppet will be installed. If ``install`` is set to ``false``, puppet will not
be installed. However, this will result in an error if puppet is not already
present on the system. The version of puppet to be installed can be specified
under ``version``, and defaults to ``none``, which selects the latest version
in the repos. If the ``puppet`` config key exists in the config archive, this
module will attempt to start puppet even if no installation was performed.

The module also provides keys for configuring the new puppet 4 paths and
installing the puppet package from the puppetlabs repositories:
https://docs.puppet.com/puppet/4.2/reference/whered_it_go.html
The keys are ``package_name``, ``conf_file``, ``ssl_dir`` and
``csr_attributes_path``. If unset, their values will default to
ones that work with puppet 3.x and with distributions that ship modified
puppet 4.x that uses the old paths.

Puppet configuration can be specified under the ``conf`` key. The
configuration is specified as a dictionary containing high-level ``<section>``
keys and lists of ``<key>=<value>`` pairs within each section. Each section
name and ``<key>=<value>`` pair is written directly to ``puppet.conf``. As
such,  section names should be one of: ``main``, ``master``, ``agent`` or
``user`` and keys should be valid puppet configuration options. The
``certname`` key supports string substitutions for ``%i`` and ``%f``,
corresponding to the instance id and fqdn of the machine respectively.
If ``ca_cert`` is present, it will not be written to ``puppet.conf``, but
instead will be used as the puppermaster certificate. It should be specified
in pem format as a multi-line string (using the ``|`` yaml notation).

Additionally it's possible to create a csr_attributes.yaml for
CSR attributes and certificate extension requests.
See https://puppet.com/docs/puppet/latest/config_file_csr_attributes.html

**Internal name:** ``cc_puppet``

**Module frequency:** per instance

**Supported distros:** all

**Config keys**::

    puppet:
        install: <true/false>
        version: <version>
        conf_file: '/etc/puppet/puppet.conf'
        ssl_dir: '/var/lib/puppet/ssl'
        csr_attributes_path: '/etc/puppet/csr_attributes.yaml'
        package_name: 'puppet'
        conf:
            agent:
                server: "puppetmaster.example.org"
                certname: "%i.%f"
                ca_cert: |
                    -------BEGIN CERTIFICATE-------
                    <cert data>
                    -------END CERTIFICATE-------
        csr_attributes:
            custom_attributes:
                1.2.840.113549.1.9.7: 342thbjkt82094y0uthhor289jnqthpc2290
            extension_requests:
                pp_uuid: ED803750-E3C7-44F5-BB08-41A04433FE2E
                pp_image_name: my_ami_image
                pp_preshared_key: 342thbjkt82094y0uthhor289jnqthpc2290
�N)�StringIO)�helpers)�subp)�utilz/etc/puppet/puppet.confz/var/lib/puppet/sslz/etc/puppet/csr_attributes.yaml�puppetc@seZdZdd�ZdS)�PuppetConstantscCs8||_||_tj�|d�|_tj�|jd�|_||_dS)N�certszca.pem)�	conf_path�ssl_dir�os�path�join�ssl_cert_dir�
ssl_cert_path�csr_attributes_path)�selfZpuppet_conf_fileZpuppet_ssl_dirr�log�r�</usr/lib/python3/dist-packages/cloudinit/config/cc_puppet.py�__init__as
zPuppetConstants.__init__N)�__name__�
__module__�__qualname__rrrrrr_srcCsntj�d�r tjgd�dd�nJtj�d�r@tjgd�dd�n*tj�d�r`tjgd�dd�n
|�d	�dS)
N�/etc/default/puppet)Zsedz-iz-ezs/^START=.*/START=yes/rF��capture�/bin/systemctl)r�enablezpuppet.service�/sbin/chkconfig)rr�onzASorry we do not know how to enable puppet services on this system)rr�existsr�warning)rrrr�_autostart_puppetjs
�
�r"cCsFd|vr|�d|�dS|d}t�|dd�}t�|dd�}t�|dt�}t�|dt�}	t�|dt�}
t�|d	t�}t|	|
||�}|s�|r�|�	d
�n(|r�|�d|r�|nd�|j
�||f�d
|v�rt�|j
�}
t��}dd�|
��D�}d�|�}|jt|�|j
d�|d
��D]�\}}|dk�r�t�|jd�t�|jdd�t�|j�t�|jdd�t�|j|�t�|jdd�nT|��D]J\}}|dk�r�|�dt���}|�d|���}|��}|� |||��q�t�!|j
d|j
�t�|j
|�"���qd|v�r(t�|j#t$j%|ddd��t&|�t'j'gd�dd�dS)Nrz9Skipping module named %s, no 'puppet' configuration found�installT�version�package_name�	conf_filer
rz=Puppet install set false but version supplied, doing nothing.z Attempting to install puppet %s,�latest�confcSsg|]}|���qSr)�lstrip)�.0�irrr�
<listcomp>��zhandle.<locals>.<listcomp>�
)�sourceZca_certi��rootZcertnamez%fz%iz%s.oldZcsr_attributesF)�default_flow_style)�servicer�startr)(�debugr�get_cfg_option_bool�get_cfg_option_str�PUPPET_PACKAGE_NAME�PUPPET_CONF_PATH�PUPPET_SSL_DIR�PUPPET_CSR_ATTRIBUTES_PATHrr!�distro�install_packages�	load_filer	r�DefaultingConfigParser�
splitlinesr
�	read_filer�items�
ensure_dirr
�chownbynamer�
write_filer�replace�socket�getfqdn�get_instance_id�lower�set�rename�	stringifyr�yaml�dumpr"r)�name�cfg�cloudr�_argsZ
puppet_cfgr#r$r%r&r
rZp_constants�contentsZ
puppet_configZ
cleaned_linesZcleaned_contentsZcfg_name�o�vrrr�handlezsz����
�

�


�

��rV)�__doc__rrFrM�ior�	cloudinitrrrr8r9r:r7�objectrr"rVrrrr�<module>	sG