
­­­­­­­­­­­­­­­­­­
<!DOCTYPE html>
<html>
3
\me              	   @   s   U d Z ddlZddlZddlmZ ddlmZmZmZ ddl	m
Z
 ddlmZ ddlmZmZ ddlmZ dd	lmZ d
ZdddeegeedgdgdZeeeZ ejeZG dd dZeee
eddddZdS )z&Salt Minion: Setup and run salt minion    N)dedent)safeyamlsubputil)Cloud)Config)
MetaSchemaget_meta_doc)ALL_DISTROS)PER_INSTANCEa.  This module installs, configures and starts salt minion. If the ``salt_minion``
key is present in the config parts, then salt minion will be installed and
started. Configuration for salt minion can be specified in the ``conf`` key
under ``salt_minion``. Any conf values present there will be assigned in
``/etc/salt/minion``. The public and private keys to use for salt minion can be
specified with ``public_key`` and ``private_key`` respectively. Optionally if
you have a custom package name, service name or config directory you can
specify them with ``pkg_name``, ``service_name`` and ``config_dir``.

Salt keys can be manually generated by: ``salt-key --gen-keys=GEN_KEYS``,
where ``GEN_KEYS`` is the name of the keypair, e.g. 'minion'.  The keypair
will be copied to ``/etc/salt/pki`` on the minion instance.
Zcc_salt_minionzSalt MinionzSetup and run salt minionai              salt_minion:
                pkg_name: salt-minion
                service_name: salt-minion
                config_dir: /etc/salt
                conf:
                    file_client: local
                    fileserver_backend:
                      - gitfs
                    gitfs_remotes:
                      - https://github.com/_user_/_repo_.git
                    master: salt.example.com
                grains:
                    role:
                        - web
                public_key: |
                    ------BEGIN PUBLIC KEY-------
                    <key data>
                    ------END PUBLIC KEY-------
                private_key: |
                    ------BEGIN PRIVATE KEY------
                    <key data>
                    ------END PRIVATE KEY-------
                pki_dir: /etc/salt/pki/minion
            salt_minion)idnametitledescriptionZdistrosZ	frequencyZexamplesZactivate_by_schema_keysc               @   s   e Zd ZdZdd ZdS )SaltConstantsz>
    defines default distribution specific salt variables
    c             C   sh   t j rd| _d| _d| _nd| _d| _d| _t j|d| j| _t j|d| j| _t j|d| j| _d S )	Nzpy-saltr   z/usr/local/etc/saltzsalt-minionz	/etc/saltpkg_nameZ
config_dirZservice_name)r   Z
is_FreeBSDr   srv_nameconf_dirZget_cfg_option_str)selfcfg r   $/usr/lib/python3.6/cc_salt_minion.py__init__T   s    zSaltConstants.__init__N)__name__
__module____qualname____doc__r   r   r   r   r   r   O   s   r   )r   r   cloudargsreturnc             C   s  d|krt jd|  d S |d }t|d}|jj|jg tj|j d }d|kr~t	j
j|jd}|jd}tj|tj| d|krt	j
j|jd}tj|jd}	tj||	 d|kod|krXt	j
j|jd	}
t	j
j|
st	j
j|jd
}
|jd|
}tjdL tj| t	j
j|d}t	j
j|d}tj||d  tj||d  W d Q R X t|ol|jddk }|jj|rdnd|j |jj|rdnd|j |stjdddgdd d S )Nr   z?Skipping module named %s, no 'salt_minion' key in configuration)r   ZconfZminionZgrainsZ
public_keyZprivate_keyz
pki/minionZpkipki_dir?   z
minion.pubz
minion.pemZfile_clientZlocalenabledisableZrestartstopz	salt-callz--localzstate.applyF)Zcapture)LOGdebugr   ZdistroZinstall_packagesr   r   Z
ensure_dirr   ospathjoingetZ
write_filer   dumpsisdirumaskboolZmanage_servicer   r   )r   r   r   r   Zs_cfgconstZminion_dataZminion_configZgrains_configZgrains_dataZpki_dir_defaultr!   Zpub_nameZpem_nameZminion_daemonr   r   r   handlej   sJ    


r1   )r   Zloggingr(   textwrapr   Z	cloudinitr   r   r   Zcloudinit.cloudr   Zcloudinit.configr   Zcloudinit.config.schemar   r	   Zcloudinit.distrosr
   Zcloudinit.settingsr   ZMODULE_DESCRIPTIONmetaZ	getLoggerr   r&   r   strlistr1   r   r   r   r   <module>   s.   
