Puppet 6.0.2 : Install on Ubuntu 18.04 (bionic)
Puppet
Puppet is a configuration management tool. The user describes system resources and their state, either using a Ruby DSL or Puppet's declarative language. This system information is stored in files called manifests file. Puppet discovers the system information via a utility called Facter, and compiles the manifests into a system-specific catalog containing resources and resource dependency, which are applied against the target systems. Any actions taken by Puppet are then reported.
We can configure systems with Puppet either in a client-server architecture, using the Puppet agent and Puppet master applications, or in a stand-alone architecture, using the Puppet apply application.
Puppet is available in two versions, Enterprise and Open source.
In an agent-master architecture, a Puppet master server controls the configuration information, and each managed agent node requests its own configuration catalog from the master. Each Puppet agent periodically sends facts to the Puppet master, and requests a catalog. The master compiles and returns that node's catalog, using several sources of information it has access to.
Once it receives a catalog, Puppet agent applies it to the node by checking each resource the catalog describes.
After applying the catalog, the agent sends a report to the Puppet master.
Before starting, we will need to configure /etc/hosts and /etc/hostname file on Server node and agent node, so they can communicate with each other.
- /etc/hosts:
172.31.41.98 puppet
/etc/hostname:
puppet
- /etc/hosts:
172.31.41.98 puppet
/etc/hostname:
agent
On the server node
On the agent node:
Restart the nodes, and then we'll see the hostnames have been switched to the new names:
ubuntu@puppet:~$ ubuntu@agent:~$
Install the puppetlabs-release repository into Ubuntu 18.04 and update our system.
Ref: Puppet Server: Installing From Packages
This process downloads a .deb file that will configure the repositories for us:
$ wget https://apt.puppetlabs.com/puppet6-release-bionic.deb $ sudo dpkg -i puppet6-release-bionic.deb $ sudo apt update
Install the puppet server:
$ sudo apt-get install puppetserver
Generate a root and intermediate signing CA for Puppet Server:
root@puppet:~# puppetserver ca setup
Start the Puppet Server service:
$ sudo systemctl start puppetserver
Or
$ sudo service puppetserver start
$ puppetserver --version puppetserver version: 6.0.2
By default, Puppet Server is configured to use 2GB of RAM. However, if we want to experiment with Puppet Server on a VM, we can safely allocate as little as 512MB of memory. To change the Puppet Server memory allocation, we can edit the init config file, /etc/default/puppetserver:
Update the line:
# Modify this if you'd like to change the memory allocation, enable JMX, etc JAVA_ARGS="-Xms2g -Xmx2g"
Replace 2g with the amount of memory you want to allocate to Puppet Server. For example, to allocate 1GB of memory, use JAVA_ARGS="-Xms1g -Xmx1g"; for 512MB, use JAVA_ARGS="-Xms512m -Xmx512m".
Update /etc/puppet/puppet.conf and add the dns_alt_names line to the section [main], replacing puppet.example.com with our own FQDN:
[main] server=puppet
Start Puppet server and enable it to start on boot time with the following command:
$ sudo systemctl start puppetserver $ sudo systemctl enable puppetserver
On agent nodes running Ubuntu 18.04, use this command to install Puppet (Installing Puppet agent: Linux):
$ wget https://apt.puppetlabs.com/puppet6-release-bionic.deb $ sudo dpkg -i puppet6-release-bionic.deb $ sudo apt update $ sudo apt-get install puppet-agent
Start the puppet service:
$ sudo /opt/puppetlabs/bin/puppet resource service puppet ensure=running enable=true
Modify our Puppet Agent's host file (/etc/hosts) to resolve the Puppet master IP as puppet:
172.31.41.98 puppet
Add the server value to the [main] section of the node's /etc/puppet/puppet.conf file, replacing puppet.example.com with the FQDN of our Puppet master:
[main] server=puppet.example.com
Restart the Puppet service:
$ sudo systemctl start puppet $ sudo systemctl enable puppet
On the Puppet master:
Run sudo /opt/puppetlabs/bin/puppetserver ca list to see any outstanding requests.
Run sudo /opt/puppetlabs/bin/puppetserver ca sign <NAME> to sign a request.
As each Puppet agent runs for the first time, it submits a certificate signing request (CSR) to the CA Puppet master. You must log into that server to check for and sign certificates. After an agent's certificate is signed, it regularly fetches and applies configuration catalogs from the Puppet master.
On the master node:
root@puppet:~# puppetserver ca list Requested Certificates: agent.ec2.internal (SHA256) B6:D5:16:E2:0D:CA:21:4A:94:48:19:06:7B:85:8A:F7:21:EC:2E:8D:D6:14:3E:D4:FA:58:4A:94:8F:BE:B5:0D ip-172-31-33-206.ec2.internal (SHA256) 72:FE:09:08:0F:7A:14:B1:34:41:FA:C4:7C:C0:5F:31:FA:57:B9:B3:F7:8C:33:5B:94:96:25:88:2A:CC:86:E4 root@puppet:~# puppetserver ca sign --certname agent.ec2.internal Successfully signed certificate request for agent.ec2.internal
On the agent node:
root@agent:~# puppet agent -t Info: Using configured environment 'production' Info: Retrieving pluginfacts Info: Retrieving plugin Info: Retrieving locales Info: Caching catalog for agent.ec2.internal Info: Applying configuration version '1540876180' Notice: Applied catalog in 0.01 seconds
To create a simple Puppet manifest to install Nginx web server. Let's start by creating a folder path for the nginx class. The /etc/puppet/modules directory will host all our modules.
$ sudo mkdir -p /etc/puppet/modules/nginx/manifests
Then, create nginx resource by creating a file, /etc/puppet/modules/nginx/manifests/nginx.pp:
class nginx { package { 'nginx': ensure => installed, } service { 'nginx': ensure => true, enable => true, require => Package['nginx'], } }
We may want to run the puppet agent --test command (from the agent node), if we do not want to wait for the scheduled Puppet agent pull.
On the Puppet master, install the puppetlabs-apache module from Puppet Forge:
# ./puppet module install puppetlabs-apache Notice: Preparing to install into /etc/puppetlabs/code/environments/production/modules ... Notice: Downloading from https://forgeapi.puppet.com ... Notice: Installing -- do not interrupt ... /etc/puppetlabs/code/environments/production/modules |- puppetlabs-apache (v3.4.0) |-- puppetlabs-concat (v5.1.0) |-- puppetlabs-stdlib (v5.1.0)
Now in /etc/puppet/manifest/site.pp:
node 'agent01' { class { 'apache': } # use apache module apache::vhost { 'example.com': # define vhost resource port => '80', docroot => '/var/www/html' } }
Puppet
Ph.D. / Golden Gate Ave, San Francisco / Seoul National Univ / Carnegie Mellon / UC Berkeley / DevOps / Deep Learning / Visualization