Aprenda a instalar un servidor y un agente Puppet y a configurarlos para que se comuniquen entre ellos.
Puppet es una de las herramientas de gestión de la configuración más adoptadas por las empresas en el mundo de DevOps. Como Ingeniero DevOpsdebe saber cómo configurar una marioneta en su sistema.
Pero antes de empezar, déjeme decirle que instalar una marioneta no es una tarea fácil en absoluto. Si se salta un solo paso o si cambia el flujo de pasos mencionados en este tutorial, incluso en un solo lugar, podría estar rascándose la cabeza todo el día con un montón de errores, pero su instalación estaría incompleta. Por lo tanto, siga cada paso con mucho cuidado.
Marioneta tiene una arquitectura cliente-servidor, que consiste en un puppet master (servidor) y agentes puppet (cliente). El puppet master dispone de todas las configuraciones, y compila y suministra las configuraciones a los puppet agents. Los agentes puppet envían los hechos al puppet master solicitando catálogos en intervalos. Puppet Master devuelve el catálogo solicitado al agente títere. A continuación, el agente títere aplica ese catálogo en el nodo e informa al maestro.
Ahora que tiene una comprensión básica de Puppet vamos a empezar y a configurar un Puppet Master y un Puppet Agent.
Si es usted un principiante absoluto, puede que le interese este curso de vídeo en línea.
Detalles medioambientales
Estoy utilizando 2 máquinas Ubuntu 18.04. Una actuará como puppet master y la otra como puppet agent. A continuación se muestran los detalles de las máquinas:
Puppet Master (Servidor)
- Nombre de host: puppet, puppet.geekflate.com
- Dirección IP: 192.168.0.108
Agente Puppet (Cliente)
- Nombre de host: puppetagent
- Dirección IP: 192.168.0.107
Instalación del Servidor Puppet
Antes de comenzar la instalación, necesito editar el archivo /etc/hosts
tanto en el maestro como en el agente para que puedan resolverse mutuamente.
En el nodo maestro
geekflare@puppet-master:~$ 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 agente
geekflare@puppet-agent:~$ 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 puppet en mi nodo maestro y actualizarlo.
Descargue el repositorio de puppet.
geekflare@puppet-master:~$ 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]
Añadir y configurar puppet 6 repo.
geekflare@puppet-master:~$ 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.
geekflare@puppet-master:~$ 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 Puppet
Vamos a ejecutar el siguiente comando en el nodo maestro para instalar el servidor puppet en él.
geekflare@puppet-master:~$ 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 Puppet
Editar el puppetserver
como se muestra a continuación. Esto para configurar la JVM del servidor puppet.
geekflare@puppet-master:~$ 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 puppet para modificar la configuración del servidor puppet.
geekflare@puppet-master:~$ 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.
geekflare@puppet-master:~$ 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 puppet.
geekflare@puppet-master:~$ sudo systemctl start puppetserver
geekflare@puppet-master:~$ 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 Puppet
Siga los siguientes pasos en el nodo agente como lo hizo para el sistema maestro. El repositorio Puppet debe estar presente en todos los nodos agentes.
geekflare@puppet-agent:~$ wget https://apt.puppetlabs.com/puppet6-release-bionic.deb
geekflare@puppet-agent:~$ sudo dpkg -i puppet6-release-bionic.deb
geekflare@puppet-agent:~$ sudo apt update
Ejecute el siguiente comando en el nodo agente para instalar el agente puppet.
geekflare@puppet-agent:~$ 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 Puppet
Edite el archivo de configuración de puppet en el nodo agente.
geekflare@puppet-agent:~$ 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 puppet. Este comando también se iniciará automáticamente después de que arranque.
geekflare@puppet-agent:~$ sudo /opt/puppetlabs/bin/puppet resource service puppet ensure=running enable=true
service { 'puppet':
ensure => 'running',
enable => 'true',
}
Generar y firmar certificados
Cuando el agente se inicia por primera vez, envía una solicitud de firma de certificado al maestro de marionetas. El maestro debe comprobar y firmar este certificado. Después de esto, el agente obtendrá los catálogos del maestro y los aplicará a los nodos del agente con regularidad.
Ahora que el agente puppet se está ejecutando ejecute el siguiente comando en el nodo maestro para comprobar si ha recibido alguna solicitud de firma de certificado.
En el nodo maestro
geekflare@puppet-master:~$ 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
Firme el certificado enviado por el agente.
geekflare@puppet-master:~$ 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 comprobar toda la lista de certificados. Uno de los certificados ya está ahí, es por defecto del nodo maestro, y el otro es del nodo agente.
geekflare@puppet-master:~$ 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 agente
Ahora ejecute este comando para comprobar si se ha establecido la conexión entre los nodos maestro y agente, y todo funciona correctamente.
geekflare@puppet-agent:~$ 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
Vamos a ejecutar un sencillo ejemplo de puppet. Crearé un simple manifiesto de marioneta, que crea un directorio con un permiso determinado.
En el Nodo Maestro:
geekflare@puppet-master:~$ sudo gedit /etc/puppetlabs/code/environments/production/manifests/site.pp
Ponga el siguiente contenido.
node 'puppetagent' { # Applies only to mentioned node. If nothing mentioned, applies to all.
file { '/home/test': # Resource type file
ensure => 'directory', # Create a directory
owner => 'root', # Ownership
group => 'root', # Group Name
mode => '0755', # Directory permissions
}
}
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 agente.
En el nodo agente
geekflare@puppet-agent:~$ 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
Ejecute el ls
para comprobar si el director se ha creado correctamente.
geekflare@puppet-agent:~$ 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
¡Ya está!
Conclusión
Este era un ejemplo sencillo para demostrar su funcionamiento. Pero imagine un escenario mayor, donde tenga que instalar o aplicar una determinada configuración en cientos de servidores. Puppet puede ayudarle a conseguirlo en cuestión de minutos.
Si se dedica a la automatización y le interesa saber más, puede consultar esto Curso Udemyque habla de Ansible, Puppet y Salt.