Puppet has 2 distributes :
1. WEBrick Puppet (Apache) - Naming of services like puppetmaster and puppetagent etc.
2. Puppet Labs (Use in this tutorial)
Puppet Server: Installing From Packages
Puppet Collections and packages
$ wget https://apt.puppetlabs.com/puppetlabs-release-pc1-xenial.deb
$ sudo dpkg -i puppetlabs-release-pc1-xenial.deb
$ sudo apt update
$ sudo apt-get install puppetserver
$ sudo systemctl start puppetserver
Puppet agent: Linux
Puppet Collections and packages
$ wget https://apt.puppetlabs.com/puppetlabs-release-pc1-trusty.deb
$ sudo dpkg -i puppetlabs-release-pc1-trusty.deb
$ sudo apt-get update
** Before startup install & configure agent do not forget add Puppet Server(Master) in /etc/hosts at agent side. Default name of Puppet Server is puppet so you map that name to correct IP address.
ubuntu@node1:~$ sudo vi /etc/hosts
ubuntu@node1:~$
ubuntu@node1:~$ wget https://apt.puppetlabs.com/puppetlabs-release-pc1-trusty.deb
--2016-09-10 22:52:47-- https://apt.puppetlabs.com/puppetlabs-release-pc1-trusty.deb
Resolving apt.puppetlabs.com (apt.puppetlabs.com)... 198.58.114.168, 2600:3c00::f03c:91ff:fe69:6bf0
Connecting to apt.puppetlabs.com (apt.puppetlabs.com)|198.58.114.168|:443... connected.
HTTP request sent, awaiting response... 200 OK
Length: 13652 (13K) [application/x-debian-package]
Saving to: 'puppetlabs-release-pc1-trusty.deb'
100%[================================================================================================================>] 13,652 44.3KB/s in 0.3s
2016-09-10 22:52:49 (44.3 KB/s) - 'puppetlabs-release-pc1-trusty.deb' saved [13652/13652]
ubuntu@node1:~$ sudo dpkg -i puppetlabs-release-pc1-trusty.deb
Selecting previously unselected package puppetlabs-release-pc1.
(Reading database ... 57362 files and directories currently installed.)
Preparing to unpack puppetlabs-release-pc1-trusty.deb ...
Unpacking puppetlabs-release-pc1 (1.1.0-2trusty) ...
Setting up puppetlabs-release-pc1 (1.1.0-2trusty) ...
ubuntu@node1:~$ sudo apt-get update
Hit https://apt.dockerproject.org ubuntu-trusty InRelease
Ign http://apt.puppetlabs.com trusty InRelease
Hit https://apt.dockerproject.org ubuntu-trusty/main amd64 Packages
Ign http://archive.ubuntu.com trusty InRelease
Get:1 https://apt.dockerproject.org ubuntu-trusty/main Translation-en
Get:2 http://apt.puppetlabs.com trusty Release.gpg [841 B]
Ign https://apt.dockerproject.org ubuntu-trusty/main Translation-en
Get:3 http://archive.ubuntu.com trusty-updates InRelease [65.9 kB]
Get:4 http://apt.puppetlabs.com trusty Release [54.2 kB]
Get:5 http://archive.ubuntu.com trusty-security InRelease [65.9 kB]
Get:6 http://apt.puppetlabs.com trusty/PC1 amd64 Packages [15.6 kB]
Hit http://archive.ubuntu.com trusty Release.gpg
Get:7 http://archive.ubuntu.com trusty-updates/main amd64 Packages [889 kB]
Get:8 http://archive.ubuntu.com trusty-updates/restricted amd64 Packages [15.9 kB]
Get:9 http://archive.ubuntu.com trusty-updates/universe amd64 Packages [373 kB]
Get:10 http://archive.ubuntu.com trusty-updates/multiverse amd64 Packages [14.8 kB]
Ign http://apt.puppetlabs.com trusty/PC1 Translation-en
Get:11 http://archive.ubuntu.com trusty-updates/main Translation-en [431 kB]
Get:12 http://archive.ubuntu.com trusty-updates/multiverse Translation-en [7661 B]
Get:13 http://archive.ubuntu.com trusty-updates/restricted Translation-en [3699 B]
Get:14 http://archive.ubuntu.com trusty-updates/universe Translation-en [197 kB]
Get:15 http://archive.ubuntu.com trusty-security/main amd64 Packages [524 kB]
Get:16 http://archive.ubuntu.com trusty-security/restricted amd64 Packages [13.0 kB]
Get:17 http://archive.ubuntu.com trusty-security/universe amd64 Packages [136 kB]
Get:18 http://archive.ubuntu.com trusty-security/multiverse amd64 Packages [4990 B]
Get:19 http://archive.ubuntu.com trusty-security/main Translation-en [288 kB]
Get:20 http://archive.ubuntu.com trusty-security/multiverse Translation-en [2570 B]
Get:21 http://archive.ubuntu.com trusty-security/restricted Translation-en [3206 B]
Get:22 http://archive.ubuntu.com trusty-security/universe Translation-en [81.3 kB]
Hit http://archive.ubuntu.com trusty Release
Hit http://archive.ubuntu.com trusty/main amd64 Packages
Hit http://archive.ubuntu.com trusty/restricted amd64 Packages
Hit http://archive.ubuntu.com trusty/universe amd64 Packages
Hit http://archive.ubuntu.com trusty/multiverse amd64 Packages
Hit http://archive.ubuntu.com trusty/main Translation-en
Hit http://archive.ubuntu.com trusty/multiverse Translation-en
Hit http://archive.ubuntu.com trusty/restricted Translation-en
Hit http://archive.ubuntu.com trusty/universe Translation-en
Fetched 3187 kB in 18s (171 kB/s)
Reading package lists... Done
ubuntu@node1:~$ sudo apt-get install 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 12 not upgraded.
Need to get 15.1 MB of archives.
After this operation, 81.8 MB of additional disk space will be used.
Get:1 http://apt.puppetlabs.com/ trusty/PC1 puppet-agent amd64 1.6.2-1trusty [15.1 MB]
Fetched 15.1 MB in 0s (60.7 MB/s)
perl: warning: Setting locale failed.
perl: warning: Please check that your locale settings:
LANGUAGE = (unset),
LC_ALL = (unset),
LC_TIME = "th_TH.UTF-8",
LC_MONETARY = "th_TH.UTF-8",
LC_ADDRESS = "th_TH.UTF-8",
LC_TELEPHONE = "th_TH.UTF-8",
LC_NAME = "th_TH.UTF-8",
LC_MEASUREMENT = "th_TH.UTF-8",
LC_IDENTIFICATION = "th_TH.UTF-8",
LC_NUMERIC = "th_TH.UTF-8",
LC_PAPER = "th_TH.UTF-8",
LANG = "en_US.UTF-8"
are supported and installed on your system.
perl: warning: Falling back to the standard locale ("C").
locale: Cannot set LC_ALL to default locale: No such file or directory
Selecting previously unselected package puppet-agent.
(Reading database ... 57367 files and directories currently installed.)
Preparing to unpack .../puppet-agent_1.6.2-1trusty_amd64.deb ...
Unpacking puppet-agent (1.6.2-1trusty) ...
Processing triggers for ureadahead (0.100.0-16) ...
Setting up puppet-agent (1.6.2-1trusty) ...
update-rc.d: warning: start runlevel arguments (none) do not match pxp-agent Default-Start values (2 3 4 5)
update-rc.d: warning: stop runlevel arguments (none) do not match pxp-agent Default-Stop values (0 1 6)
Processing triggers for ureadahead (0.100.0-16) ...
ubuntu@node1:~$ sudo /opt/puppetlabs/bin/puppet resource service puppet ensure=running enable=true
2016-09-10 22:54:37.681893 WARN puppetlabs.facter - locale environment variables were bad; continuing with LANG=C LC_ALL=C
Notice: /Service[puppet]/ensure: ensure changed 'stopped' to 'running'
service { 'puppet':
ensure => 'running',
enable => 'true',
}
ubuntu@node1:~$ sudo /opt/puppetlabs/bin/puppet agent --test
2016-09-10 22:57:11.396529 WARN puppetlabs.facter - locale environment variables were bad; continuing with LANG=C LC_ALL=C
Info: Using configured environment 'production'
Info: Retrieving pluginfacts
Info: Retrieving plugin
Info: Caching catalog for node1
Info: Applying configuration version '1473523040'
Notice: Applied catalog in 0.24 seconds
Sign certificates on the CA master
nutt@nutt-pc:~/Downloads$ sudo /opt/puppetlabs/bin/puppet cert list
Warning: Facter: Could not process routing table entry: Expected a destination followed by key/value pairs, got '192.168.122.0/24 dev virbr0 proto kernel scope link src 192.168.122.1 linkdown'
"node1" (SHA256) CE:54:74:42:95:4A:C5:44:20:90:23:26:3C:63:F0:4D:71:79:12:BC:06:CC:0A:6A:ED:DE:E4:BD:AA:77:C2:A3
nutt@nutt-pc:~/Downloads$ sudo /opt/puppetlabs/bin/puppet cert sign node1
Warning: Facter: Could not process routing table entry: Expected a destination followed by key/value pairs, got '192.168.122.0/24 dev virbr0 proto kernel scope link src 192.168.122.1 linkdown'
Signing Certificate Request for:
"node1" (SHA256) CE:54:74:42:95:4A:C5:44:20:90:23:26:3C:63:F0:4D:71:79:12:BC:06:CC:0A:6A:ED:DE:E4:BD:AA:77:C2:A3
Notice: Signed certificate request for node1
Notice: Removing file Puppet::SSL::CertificateRequest node1 at '/etc/puppetlabs/puppet/ssl/ca/requests/node1.pem'
Master-Agent Simple Setup
Main file /etc/puppetlabs/code/environments/production/manifests/site.pp
All node effects
file {'/tmp/example-ip': # resource type file and filename
ensure => present, # make sure it exists
mode => '0644', # file permissions
content => "Here is my Public IP Address: ${ipaddress_eth0}.\n", # note the ipaddress_eth0 fact
}
Specific node effects
node 'ns1', 'ns2' { # applies to ns1 and ns2 nodes
file {'/tmp/dns': # resource type file and filename
ensure => present, # make sure it exists
mode => '0644',
content => "Only DNS servers get this file.\n",
}
}
node default {} # applies to nodes that aren't explicitly defined
Resource propagate to nodes depend on their schedule or take effect them immediately with 'puppet agent --test'
As a result of above configuration, all node will have a file name 'dns' and 'example-ip' in /tmp directory
Puppet Apply (standalone run puppet file)
Optional, set environment variable: only root user can run Puppet
PATH=/opt/puppetlabs/bin:$PATH;export PATH
docker_example.pp
include 'docker'
docker::run { 'helloworld':
image => 'ubuntu:precise',
command => '/bin/sh -c "while true; do echo hello world; sleep 1; done"',
}
Troubleshooting
Some of client may have an error when run Puppet command like below:
root@node2:~/Docker/puppet# facter
2016-09-11 00:21:25.117804 WARN puppetlabs.facter - locale environment variables were bad; continuing with LANG=C LC_ALL=C
2016-09-11 00:21:25.146927 FATAL puppetlabs.facter - unhandled exception: boost::filesystem::current_path: No such file or directory
root@node2:~/Docker/puppet# puppet agent --test
2016-09-11 00:23:03.006097 WARN puppetlabs.facter - locale environment variables were bad; continuing with LANG=C LC_ALL=C
terminate called after throwing an instance of 'boost::filesystem::filesystem_error'
what(): boost::filesystem::current_path: No such file or directory
Aborted (core dumped)
This because server do not have some library such as '
libboost-filesystem-dev'