¿Cómo instalar Puppet 6 en Ubuntu 18?

Aprenda a instalar y configurar un servidor y un agente de Puppet para que se comuniquen entre sí.

Puppet es una de las herramientas de administración de configuración más adoptadas por las empresas en el mundo DevOps. Como ingeniero de DevOps, debe saber cómo configurar una marioneta en su sistema.

Pero antes de comenzar, déjame decirte que instalar una marioneta no es una tarea nada fácil. Si omite un solo paso o si cambia el flujo de pasos mencionado en este tutorial, incluso en un solo lugar, es posible que esté rascándose la cabeza todo el día con muchos errores, pero su configuración estará incompleta. Por lo tanto, siga cada paso con mucho cuidado.

Marioneta tiene una arquitectura cliente-servidor, que consiste en un titiritero (servidor) y agentes titiritero (cliente). Puppet Master tiene todas las configuraciones y compila y proporciona las configuraciones a los agentes de marionetas. Los agentes de marionetas envían los hechos al titiritero solicitando catálogos a intervalos. Puppet Master envía el reverso del catálogo solicitado al agente de marionetas. Puppet Agent luego aplica ese catálogo en el nodo e informa al maestro.

Ahora que tiene una comprensión básica de Puppet, comencemos y configuremos un Puppet Master y Puppet Agent.

Si es un principiante absoluto, puede que le guste tomar este curso de vídeo en línea.

Detalles del entorno

Estoy usando 2 máquinas Ubuntu 18.04. Uno actuará como titiritero y el otro como agente titiritero. A continuación se muestran los detalles de las máquinas:

Titiritero (Servidor)

  • Nombre de host: marioneta, marioneta.geekflate.com
  • Dirección IP: 192.168.0.108

Agente de marionetas (cliente)

  • Nombre de host: agente de marionetas
  • Dirección IP: 192.168.0.107

Instalación del servidor de marionetas

Antes de comenzar la instalación, necesito editar el /etc/hosts archivo tanto en el maestro como en el agente para que puedan resolverse entre sí.

En el nodo maestro

[email protected]:~$ sudo gedit /etc/hosts

[sudo] password for geekflare:

127.0.0.1 localhost
127.0.1.1 geekflare
192.168.0.108 puppet puppet.geekflare.com

En el nodo del agente

[email protected]:~$ sudo gedit /etc/hosts

127.0.0.1 localhost
127.0.1.1 geekflare
192.168.0.107 puppetagent
192.168.0.108 puppet puppet.geekflare.com

­Ahora, necesito obtener un repositorio de marionetas en mi nodo principal y actualizarlo.

Descarga el repositorio de marionetas.

[email protected]:~$ wget https://apt.puppetlabs.com/puppet6-release-bionic.deb

--2019-10-15 15:41:34-- https://apt.puppetlabs.com/puppet6-release-bionic.deb

Resolving apt.puppetlabs.com (apt.puppetlabs.com)... 99.86.19.107, 99.86.19.59, 99.86.19.2, ...

Connecting to apt.puppetlabs.com (apt.puppetlabs.com)|99.86.19.107|:443... connected.

HTTP request sent, awaiting response... 200 OK

Length: 11736 (11K) [application/x-debian-package]

Saving to: ‘puppet6-release-bionic.deb’

puppet6-release-bio 100%[===================>] 11.46K --.-KB/s in 0s     

2019-10-15 15:41:34 (236 MB/s) - ‘puppet6-release-bionic.deb’ saved [11736/11736]

Agregue y configure el repositorio de Puppet 6.

[email protected]:~$ sudo dpkg -i puppet6-release-bionic.deb

Selecting previously unselected package puppet6-release.

(Reading database ... 187041 files and directories currently installed.)

Preparing to unpack puppet6-release-bionic.deb ...

Unpacking puppet6-release (6.0.0-5bionic) ...

Setting up puppet6-release (6.0.0-5bionic) ...

Actualice la lista de repositorios.

[email protected]:~$ sudo apt update

Hit:1 https://download.docker.com/linux/ubuntu bionic InRelease

Hit:2 http://security.ubuntu.com/ubuntu cosmic-security InRelease             

Hit:3 http://ppa.launchpad.net/ansible/ansible/ubuntu cosmic InRelease        

Get:4 http://download.virtualbox.org/virtualbox/debian cosmic InRelease [4,429 B]

Get:5 http://apt.puppetlabs.com bionic InRelease [85.3 kB]                    

Hit:6 http://us.archive.ubuntu.com/ubuntu cosmic InRelease                    

Hit:7 http://us.archive.ubuntu.com/ubuntu cosmic-updates InRelease            

Get:8 http://download.virtualbox.org/virtualbox/debian cosmic/contrib amd64 Packages [1,466 B]

Get:9 http://apt.puppetlabs.com bionic/puppet6 all Packages [13.5 kB]

Hit:10 http://us.archive.ubuntu.com/ubuntu cosmic-backports InRelease

Get:11 http://apt.puppetlabs.com bionic/puppet6 i386 Packages [13.5 kB]

Get:12 http://apt.puppetlabs.com bionic/puppet6 amd64 Packages [32.3 kB]

Fetched 151 kB in 2s (61.9 kB/s) 

Reading package lists... Done

Building dependency tree      

Reading state information... Done

234 packages can be upgraded. Run 'apt list --upgradable' to see them.

Instalación del servidor de marionetas

Ejecutemos el siguiente comando en el nodo maestro para instalar el servidor de marionetas en él.

[email protected]:~$ sudo apt install -y puppetserver

Reading package lists... Done

Building dependency tree      

Reading state information... Done

The following additional packages will be installed:

 ca-certificates-java java-common openjdk-8-jre-headless puppet-agent

Suggested packages:

 default-jre fonts-dejavu-extra fonts-ipafont-gothic fonts-ipafont-mincho

 fonts-wqy-microhei fonts-wqy-zenhei

The following NEW packages will be installed:

 ca-certificates-java java-common openjdk-8-jre-headless puppet-agent

 puppetserver

0 upgraded, 5 newly installed, 0 to remove and 234 not upgraded.

Need to get 109 MB of archives.

After this operation, 287 MB of additional disk space will be used.

Get:1 http://us.archive.ubuntu.com/ubuntu cosmic/main amd64 java-common all 0.68ubuntu1 [6,988 B]

Get:2 http://apt.puppetlabs.com bionic/puppet6 amd64 puppet-agent amd64 6.10.1-1bionic [19.9 MB]

Get:3 http://us.archive.ubuntu.com/ubuntu cosmic-updates/universe amd64 openjdk-8-jre-headless amd64 8u212-b03-0ubuntu1.18.10.1 [27.2 MB]

Get:4 http://apt.puppetlabs.com bionic/puppet6 amd64 puppetserver all 6.7.1-1bionic [61.5 MB]

Get:5 http://us.archive.ubuntu.com/ubuntu cosmic/main amd64 ca-certificates-java all 20180516ubuntu1 [12.3 kB]

Fetched 109 MB in 1min 41s (1,072 kB/s)                                       

Unpacking puppetserver (6.7.1-1bionic) ...

Setting up puppet-agent (6.10.1-1bionic) ...

Created symlink /etc/systemd/system/multi-user.target.wants/puppet.service → /lib/systemd/system/puppet.service.

Created symlink /etc/systemd/system/multi-user.target.wants/pxp-agent.service → /lib/systemd/system/pxp-agent.service.

Removed /etc/systemd/system/multi-user.target.wants/pxp-agent.service.

Setting up java-common (0.68ubuntu1) ...

Processing triggers for libc-bin (2.28-0ubuntu1) ...

Processing triggers for systemd (239-7ubuntu10.12) ...

Processing triggers for man-db (2.8.4-2) ...

Processing triggers for ca-certificates (20180409) ...

Updating certificates in /etc/ssl/certs...

0 added, 0 removed; done.

Running hooks in /etc/ca-certificates/update.d...

done.

Setting up ca-certificates-java (20180516ubuntu1) ...

head: cannot open '/etc/ssl/certs/java/cacerts' for reading: No such file or directory

Adding debian:SSL.com_EV_Root_Certification_Authority_ECC.pem

Adding debian:ssl-cert-snakeoil.pem

Adding debian:SwissSign_Gold_CA_-_G2.pem

Adding debian:SZAFIR_ROOT_CA2.pem

Adding debian:OpenTrust_Root_CA_G3.pem

Adding debian:TWCA_Root_Certification_Authority.pem

Adding debian:QuoVadis_Root_CA_2_G3.pem

Adding debian:DST_Root_CA_X3.pem

Adding debian:SecureSign_RootCA11.pem

Adding debian:QuoVadis_Root_CA_1_G3.pem

Adding debian:T-TeleSec_GlobalRoot_Class_3.pem

Adding debian:Go_Daddy_Root_Certificate_Authority_-_G2.pem

Adding debian:Actalis_Authentication_Root_CA.pem

Adding debian:Chambers_of_Commerce_Root_-_2008.pem

done.

Processing triggers for ca-certificates (20180409) ...

Updating certificates in /etc/ssl/certs...

0 added, 0 removed; done.

Running hooks in /etc/ca-certificates/update.d...

done.

done.

Setting up openjdk-8-jre-headless:amd64 (8u212-b03-0ubuntu1.18.10.1) ...

Setting up puppetserver (6.7.1-1bionic) ...

usermod: no changes

Processing triggers for systemd (239-7ubuntu10.12) ...

Configuración del servidor de marionetas

Editar el puppetserver archivo, como se muestra a continuación. Esto para configurar la JVM del servidor de marionetas.

[email protected]:~$ sudo gedit /etc/default/puppetserver

 
# Modify this if you'd like to change the memory allocation, enable JMX, etc

JAVA_ARGS="-Xms512m -Xmx512m -Djruby.logger.class=com.puppetlabs.jruby_utils.jruby.Slf4jLogger"

Edite el archivo de configuración de marionetas para modificar la configuración del servidor de marionetas.

[email protected]:~$ sudo gedit /etc/puppetlabs/puppet/puppet.conf


# This file can be used to override the default puppet settings.

# See the following links for more details on what settings are available:

# - https://puppet.com/docs/puppet/latest/config_important_settings.html

# - https://puppet.com/docs/puppet/latest/config_about_settings.html

# - https://puppet.com/docs/puppet/latest/config_file_main.html

# - https://puppet.com/docs/puppet/latest/configuration.html

[master]

vardir = /opt/puppetlabs/server/data/puppetserver

logdir = /var/log/puppetlabs/puppetserver

rundir = /var/run/puppetlabs/puppetserver

pidfile = /var/run/puppetlabs/puppetserver/puppetserver.pid

codedir = /etc/puppetlabs/code

dns_alt_names = puppet,puppet.geekflare.com

[main]

certname = puppet.geekflare.com

server = puppet.geekflare.com

environment = production

runinterval = 15m

Puppet Server necesita generar una firma raíz e intermedia, CA.

[email protected]:~$ sudo /opt/puppetlabs/bin/puppetserver ca setup

Generation succeeded. Find your files in /etc/puppetlabs/puppet/ssl/ca

Inicie y habilite el servicio del servidor de marionetas.

[email protected]:~$ sudo systemctl start puppetserver

[email protected]:~$ sudo systemctl enable puppetserver

Synchronizing state of puppetserver.service with SysV service script with /lib/systemd/systemd-sysv-install.

Executing: /lib/systemd/systemd-sysv-install enable puppetserver

Instalación del agente de marionetas

Siga los pasos a continuación en el nodo del agente como lo hizo para el sistema maestro. El repositorio de Puppet debe presentarse en todos los nodos de agente.

[email protected]:~$ wget https://apt.puppetlabs.com/puppet6-release-bionic.deb

[email protected]:~$ sudo dpkg -i puppet6-release-bionic.deb

[email protected]:~$ sudo apt update

Ejecute el siguiente comando en el nodo del agente para instalar el agente de marionetas.

[email protected]:~$ sudo apt install -y puppet-agent

Reading package lists... Done

Building dependency tree      

Reading state information... Done

The following NEW packages will be installed:

 puppet-agent

0 upgraded, 1 newly installed, 0 to remove and 233 not upgraded.

Need to get 19.9 MB of archives.

After this operation, 115 MB of additional disk space will be used.

Get:1 http://apt.puppetlabs.com bionic/puppet6 amd64 puppet-agent amd64 6.10.1-1bionic [19.9 MB]

Fetched 19.9 MB in 2s (8,488 kB/s)      

Selecting previously unselected package puppet-agent.

(Reading database ... 185786 files and directories currently installed.)

Preparing to unpack .../puppet-agent_6.10.1-1bionic_amd64.deb ...

Unpacking puppet-agent (6.10.1-1bionic) ...

Setting up puppet-agent (6.10.1-1bionic) ...

Created symlink /etc/systemd/system/multi-user.target.wants/puppet.service → /lib/systemd/system/puppet.service.

Created symlink /etc/systemd/system/multi-user.target.wants/pxp-agent.service → /lib/systemd/system/pxp-agent.service.

Removed /etc/systemd/system/multi-user.target.wants/pxp-agent.service.

Processing triggers for libc-bin (2.28-0ubuntu1) ...

Configuración del agente de marionetas

Edite el archivo de configuración de la marioneta en el nodo del agente.

[email protected]:~$ sudo gedit /etc/puppetlabs/puppet/puppet.conf

[main]

certname = puppetagent

server = puppet.geekflare.com

environment = production

runinterval = 15m

Ejecute el siguiente comando para iniciar el servicio de marionetas. Este comando también se iniciará automáticamente después de que se inicie.

[email protected]:~$ sudo /opt/puppetlabs/bin/puppet resource service puppet ensure=running enable=true

service  

Generar y Firmar Certificados

Cuando el agente se inicia por primera vez, envía una solicitud de firma de certificado al titiritero. El maestro debe verificar y firmar este certificado. Después de esto, el agente obtendrá catálogos del maestro y los aplicará a los nodos del agente con regularidad.

Ahora que el agente de marionetas se está ejecutando, ejecute el siguiente comando en el nodo maestro para verificar si ha recibido alguna solicitud de firma de certificado.

En el nodo maestro

[email protected]:~$ sudo /opt/puppetlabs/bin/puppetserver ca list

[sudo] password for geekflare:

Requested Certificates:

   puppetagent (SHA256) EA:68:23:B5:C3:71:2C:E6:4A:6A:3B:2F:24:F5:B8:5B:50:F7:3F:12:89:DE:B1:EB:D1:0A:74:3E:48:C3:D7:35

Firmar el certificado enviado por el agente.

[email protected]:~$ sudo /opt/puppetlabs/bin/puppetserver ca list

[sudo] password for geekflare:

Requested Certificates:

   puppetagent (SHA256) EA:68:23:B5:C3:71:2C:E6:4A:6A:3B:2F:24:F5:B8:5B:50:F7:3F:12:89:DE:B1:EB:D1:0A:74:3E:48:C3:D7:35

Ejecute el siguiente comando para verificar toda la lista de certificados. Un certificado ya existe, es un certificado predeterminado del nodo maestro y el otro es del nodo agente.

[email protected]:~$ sudo /opt/puppetlabs/bin/puppetserver ca list --all

Signed Certificates:

   puppetagent (SHA256) EA:68:23:B5:C3:71:2C:E6:4A:6A:3B:2F:24:F5:B8:5B:50:F7:3F:12:89:DE:B1:EB:D1:0A:74:3E:48:C3:D7:35

   puppet.geekflare.com (SHA256) 71:30:5B:C8:C5:CE:28:A0:60:5C:4F:39:26:D0:FC:DA:DF:0A:0F:4D:ED:D4:B1:9C:05:1A:38:2F:D6:5F:9C:06 alt names: ["DNS:puppet.geekflare.com", "DNS:puppet", "DNS:puppet.geekflare.com"]

En el nodo del agente

Ahora ejecute este comando para probar si se ha establecido la conexión entre los nodos maestro y agente, y si todo funciona bien.

[email protected]:~$ sudo /opt/puppetlabs/bin/puppet agent --test

Info: Using configured environment 'production'

Info: Retrieving pluginfacts

Info: Retrieving plugin

Info: Retrieving locales

Info: Caching catalog for puppet-agent

Info: Applying configuration version '1571171191'

Notice: Applied catalog in 0.02 seconds

Ejemplo de marioneta de muestra

Ejecutemos un ejemplo simple de marionetas. Crearé un manifiesto de títeres simple, que crea un directorio con un permiso determinado.

En el nodo maestro:

[email protected]:~$ sudo gedit /etc/puppetlabs/code/environments/production/manifests/site.pp

Pon el siguiente contenido.

node 'puppetagent' 

Ahora ejecute el siguiente comando para que un agente se comunique con el maestro y extraiga las configuraciones. Después de ejecutar este comando, debería crear ese directorio en el nodo del agente.

En el nodo del agente

[email protected]:~$ sudo /opt/puppetlabs/bin/puppet agent --test

[sudo] password for geekflare:

Info: Using configured environment 'production'

Info: Retrieving pluginfacts

Info: Retrieving plugin

Info: Retrieving locales

Info: Caching catalog for puppetagent

Info: Applying configuration version '1571333010'

Notice: /Stage[main]/Main/Node[puppetagent]/File[/home/test]/ensure: created

Notice: Applied catalog in 0.05 seconds

ejecutar el ls Comando para comprobar si el director se ha creado correctamente.

[email protected]:~$ ls -l /home/

total 32

drwxr-xr-x 13 geekflare geekflare 4096 Jul 19 08:06 geekflare

drwx------ 2 root root 16384 Oct 23 2018 lost+found

drwxr-xr-x 23 geekflare geekflare 4096 Oct 17 11:02 geekflare

drwxr-xr-x 2 root root 4096 Oct 17 13:23 test

drwxr-xr-x 2 username username 4096 Jun 29 09:38 username

¡Ahí tienes!

Conclusión

Este fue un ejemplo simple para demostrar su funcionamiento. Pero imagina un escenario más grande, donde tienes que instalar o aplicar una determinada configuración en cientos de servidores. Puppet puede ayudarte a lograrlo en minutos.

Si está involucrado en la automatización y está interesado en aprender más, puede consultar esto Curso de Udemyque habla de Ansible, Puppet y Salt.

Deja un comentario