HEX
Server: Apache/2.4.52 (Ubuntu)
System: Linux ip-10-0-8-47 6.8.0-1021-aws #23~22.04.1-Ubuntu SMP Tue Dec 10 16:31:58 UTC 2024 aarch64
User: ubuntu (1000)
PHP: 8.1.2-1ubuntu2.22
Disabled: NONE
Upload Files
File: //lib/python3/dist-packages/cloudinit/config/__pycache__/cc_puppet.cpython-310.pyc
o

�Ad�6�@sPUdZddlZddlZddlmZddlmZddlmZddl	Z	ddl
mZmZm
Z
mZmZddlmZddlmZdd	lmZmZdd
lmZmZddlmZdZd
gZdZdZdddeegeed�ed�gdgd�Z ee!d<ee �ZGdd�d�Z"dede#fdd�Z$dd�Z%eddd fd!efd"d#�Z&d$e#d%eded&ed'e'd(dfd)d*�Z(dS)+z+Puppet: Install, configure and start puppet�N)�StringIO)�Logger)�dedent)�helpers�subp�
temp_utils�
url_helper�util)�Cloud)�Config)�
MetaSchema�get_meta_doc)�ALL_DISTROS�Distro)�PER_INSTANCEzKhttps://raw.githubusercontent.com/puppetlabs/install-puppet/main/install.shz--test)�puppet-agent�puppeta>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 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.
�	cc_puppet�Puppetz#Install, configure and start puppeta`            puppet:
                install: true
                version: "7.7.0"
                install_type: "aio"
                collection: "puppet7"
                aio_install_url: 'https://git.io/JBhoQ'
                cleanup: true
                conf_file: "/etc/puppet/puppet.conf"
                ssl_dir: "/var/lib/puppet/ssl"
                csr_attributes_path: "/etc/puppet/csr_attributes.yaml"
                exec: true
                exec_args: ['--test']
                conf:
                    agent:
                        server: "puppetserver.example.org"
                        certname: "%i.%f"
                    ca_cert: |
                        -----BEGIN CERTIFICATE-----
                        MIICCTCCAXKgAwIBAgIBATANBgkqhkiG9w0BAQUFADANMQswCQYDVQQDDAJjYTAe
                        Fw0xMDAyMTUxNzI5MjFaFw0xNTAyMTQxNzI5MjFaMA0xCzAJBgNVBAMMAmNhMIGf
                        MA0GCSqGSIb3DQEBAQUAA4GNADCBiQKBgQCu7Q40sm47/E1Pf+r8AYb/V/FWGPgc
                        b014OmNoX7dgCxTDvps/h8Vw555PdAFsW5+QhsGr31IJNI3kSYprFQcYf7A8tNWu
                        1MASW2CfaEiOEi9F1R3R4Qlz4ix+iNoHiUDTjazw/tZwEdxaQXQVLwgTGRwVa+aA
                        qbutJKi93MILLwIDAQABo3kwdzA4BglghkgBhvhCAQ0EKxYpUHVwcGV0IFJ1Ynkv
                        T3BlblNTTCBHZW5lcmF0ZWQgQ2VydGlmaWNhdGUwDwYDVR0TAQH/BAUwAwEB/zAd
                        BgNVHQ4EFgQUu4+jHB+GYE5Vxo+ol1OAhevspjAwCwYDVR0PBAQDAgEGMA0GCSqG
                        SIb3DQEBBQUAA4GBAH/rxlUIjwNb3n7TXJcDJ6MMHUlwjr03BDJXKb34Ulndkpaf
                        +GAlzPXWa7bO908M9I8RnPfvtKnteLbvgTK+h+zX1XCty+S2EQWk29i2AdoqOTxb
                        hppiGMp0tT5Havu4aceCXiy2crVcudj3NFciy8X66SoECemW9UYDCb9T5D0d
                        -----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
            z�            puppet:
                install_type: "packages"
                package_name: "puppet"
                exec: false
            r)�id�name�title�description�distros�	frequency�examples�activate_by_schema_keys�metac@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)�self�puppet_conf_file�puppet_ssl_dirr'�log�r,�</usr/lib/python3/dist-packages/cloudinit/config/cc_puppet.py�__init__ps

zPuppetConstants.__init__N)�__name__�
__module__�__qualname__r.r,r,r,r-rosr�cloud�actionc	Cs`d}tD]}z|j�||�d��|}Wn
tjyYqw|s.|�d|d�t��dSdS)z8Attempts to perform action on one of the puppet services�z.servicez0Could not '%s' any of the following services: %s�, N)�PUPPET_PACKAGE_NAMES�distro�manage_servicer�ProcessExecutionError�warningr$)r+r2r3�service_managed�puppet_namer,r,r-�_manage_puppet_serviceszs ���r=cCst�|dd|g�\}}|��S)z�Get the config value for a given setting using `puppet config print`
    :param puppet_bin: path to puppet binary
    :param setting: setting to query
    �config�print)r�rstrip)�
puppet_bin�setting�out�_r,r,r-�get_config_value�srETr7c	Cs�g}|dur
d|g}|dur|d|g7}|r|dg7}tj|dd�j}tj|��dd��!}tj�|d	�}t	j
||d
d�tj|g|dd
�Wd�S1sPwYdS)a�Install puppet-agent from the puppetlabs repositories using the one-shot
    shell script

    :param distro: Instance of Distro
    :param url: URL from where to download the install script
    :param version: version to install, blank defaults to latest
    :param collection: collection to install, blank defaults to latest
    :param cleanup: whether to purge the puppetlabs repo after installation
    Nz-vz-cz	--cleanup�)�url�retriesT)�dir�	needs_exezpuppet-installi�)�modeF��capture)r�readurl�contentsr�tempdir�get_tmp_exec_pathr"r#r$r	�
write_filer)	r7rG�version�
collection�cleanup�args�content�tmpd�tmpfr,r,r-�install_puppet_aio�s 
�$�rZr�cfgr+rV�returnc 	Csd|vr|�d|�dS|d}t�|dd�}t�|dd�}t�|dd�}t�|dd�}	t�|d	d�}
tj|d
dd�}tj|d
dd�}tj|dtd�}
|	dkrVd}d}d}nd}d}d}t�|d|�}|sm|rm|�d�n\|r�|�d|rv|nd|	�|	dkr�|dur�tD]}z
|j�||f�|}Wn
t	j
y�Yq�w|s�|�dd�t��n|j�||f�n|	dkr�t|j|
|||
�n|�d|	�d}t�|dt
|d��}t�|dt
|d��}t�|dt
|d��}t||||�}d |v�r�t�|j�}t��}d!d"�|��D�}d#�|�}|jt|�|jd$�|d ��D]t\}}|d%k�rQt�|jd&�t�|j|d�t�|j�t�|j|d�t�|j|�t�|j|d�n*|��D]%\}}|d'k�rr|�d(t���}|�d)|� ��}|�!�}|�"|||��qUt�#|jd*|j�t�|j|�$���qd|v�r�t�|j%t&j'|ddd+��|�r�t(||d,�|�r�|�d-�|d.g}d/|v�r�|d/}t)|t*t+f��r�|�,|�n!t)|t-��r�|�,|�.��n|�d0t/|��|�,t0�n|�,t0�t	j	|dd1�|�rt(||d2�dSdS)3Nrz9Skipping module named %s, no 'puppet' configuration found�installTrSrT�install_type�packagesrU�execF)�default�
start_service�aio_install_url�aio�rootz/opt/puppetlabs/bin/puppetr�package_namez@Puppet install set to false but version supplied, doing nothing.z'Attempting to install puppet %s from %s�latestz+No installable puppet package in any of: %sr5z Unknown puppet install type '%s'�	conf_filer>r!�ssldirr'�csr_attributes�confcSsg|]}|���qSr,)�lstrip)�.0�ir,r,r-�
<listcomp>szhandle.<locals>.<listcomp>�
)�source�ca_certi��certnamez%fz%iz%s.old)�default_flow_style�enablezRunning puppet-agent�agent�	exec_argszOUnknown type %s provided for puppet 'exec_args' expected list, tuple, or stringrL�start)1�debugr	�get_cfg_option_bool�get_cfg_option_str�AIO_INSTALL_URLr:r6r7�install_packagesrr9r$rZrEr�	load_filer r�DefaultingConfigParser�
splitlines�	read_filer�items�
ensure_dirr!�chownbynamer%rRr&�replace�socket�getfqdn�get_instance_id�lower�set�rename�	stringifyr'�yaml�dumpr=�
isinstance�list�tuple�extend�str�split�type�PUPPET_AGENT_DEFAULT_ARGS) rr[r2r+rV�
puppet_cfgr]rSrTr^rU�run�
start_puppetdrc�puppet_userrA�puppet_packagerfr<rhr!r'�p_constantsrO�
puppet_config�
cleaned_lines�cleaned_contents�cfg_name�o�v�cmd�cmd_argsr,r,r-�handle�s������
��������


�
�
�
�

�
�r�))�__doc__r"r��ior�loggingr�textwraprr��	cloudinitrrrrr	�cloudinit.cloudr
�cloudinit.configr�cloudinit.config.schemarr
�cloudinit.distrosrr�cloudinit.settingsrr|r�r6�MODULE_DESCRIPTIONr�__annotations__rr�r=rErZr�r�r,r,r,r-�<module>sp�)��3�=�
�$������