Puppet
If there was ever a ubiquitous tool for DevOps software
deployment, it is Puppet. Even if an organization isn’t “doing
DevOps,” it probably is using Puppet somewhere. Puppet is very
good at getting applications deployed to pre-built infrastructure.
For those just getting started with deployment automation,
Puppet is a good place to start. But it is not just for beginners:
According to the company, more than 3 in 4 Fortune 100
companies use Puppet for application deployment
Puppet automates the installation and configuration of
applications on target servers. By writing scripts that define
and install application prerequisites, setting the server
variables the application requires and writing configuration
scripts for applications and daemons, a team can then
simply rerun the script to reinstall. A large user community
has already scripted many application installations. For a
large number of software applications — particularly in the
open source realm — users merely need to download the
relevant puppet script files and change what is written to the
configuration files to reflect their project.
[Puppet Master] |192.0.0.20 ---------------- 192.0.0.30| [Puppet Agent]
Master.example.com <---------------------> Agent.example.com
Lets start to configure Puppet:-
Configure Puppet Master:-
Step:1 Update Hostname
[root@master ~]# vim /etc/hosts
192.0.0.20 master.example.com
192.0.0.30 agent.example.com
#Now try to ping by name, make sure you get the server IP address
[root@master ~]# ping master.example.com
[root@master ~]# ping agent.example.com
Step:2 Configure NTP Server
[root@master ~]# yum -y install ntp ntpdate
[root@master ~]# ntpdate 0.centos.pool.ntp.org
[root@master ~]# systemctl start ntpd
[root@master ~]# systemctl enable ntpd
Step:3 Disable SELinux
[root@master ~]# vim /etc/sysconfig/selinux
SELINUX=disabled
Step:4 Add Puppet Repository
[root@master ~]# rpm -Uvh https://yum.puppetlabs.com/puppet5/puppet5-release-el-7.noarch.rpm
[root@master ~]# reboot
Step:5 Install and Configure Puppetserver
[root@master ~]# yum -y install puppetserver
[root@master ~]# vim /etc/sysconfig/puppetserver
JAVA_ARGS="-Xms1g -Xmx1g ...."
# go to the puppet configuration directory and edit the 'puppet.conf' file.
cd /etc/puppetlabs/puppet
[root@master ~]# vim puppet.conf
# add the following configuration
[master]
dns_alt_names=master.example.com,puppet
[main]
certname = master.example.com
server = master.example.com
environment = production
runinterval = 1h
[root@master ~]# systemctl start puppetserver
[root@master ~]# systemctl puppetserver
[root@master ~]# firewall-cmd --add-port=8140/tcp --permanent
[root@master ~]# firewall-cmd --reload
Configure Puppet Agent:-
Step:1 Install and Configure Puppet Agent
[root@agent ~]# yum install -y puppet-agent
[root@agent ~]# systemctl puppetserver
[root@agent ~]# cd /etc/puppetlabs/puppet
[root@agent ~]# vim puppet.conf
# Paste the following configuration.
[main]
certname = agent.example.com
server = master.example.com
environment = production
runinterval = 1h
Step:2 # Next, we will register the puppet agent to the puppet master.
# Run the command below on the puppet agent shell.
[root@agent ~]# /opt/puppetlabs/bin/puppet resource service puppet ensure=running enable=true
The puppet agent is now running on the server, and it's attempting to register itself to the puppet master.
Step:3 Now back to the puppet master shell and run the command below.
[root@master ~]# /opt/puppetlabs/bin/puppet cert list
Step:4 Sign the certificate using the command below.
[root@master ~]# /opt/puppetlabs/bin/puppet cert sign agent.example.com
Step:5 Verify the Puppet Agent Configuration from agent machine
[root@agent ~]# /opt/puppetlabs/bin/puppet agent --test
The puppet master and agent installation and configuration have been completed.
Create Your First Manifest
we will create a simple manifest for testing.
We will create the manifest for Apache httpd web server installation.
On the puppet master server, go to the '/etc/puppetlabs/code/' directory and create the new manifest file 'myconfig.pp' using vim.
[root@master ~]# cd /etc/puppetlabs/code/
[root@master ~]# cd environments/production/manifests
Create new manifest file.
[root@master ~]# vim myconfig.pp
node 'agent.example.com' {
package { 'httpd':
ensure => "installed",
}
service { 'httpd':
ensure => running,
enable => true
}
}
Run below command on agent
[root@agent ~]# /opt/puppetlabs/bin/puppet agent --test
#The command will retrieve new manifest configuration file from the puppet master and then apply it to the agent server.
Open your web browser and type the IP address of the puppet agent.
http://192.168.0.30/
And you will get the default HTTP page.
Now, You are ready to use puppet!