IT Infrastructure with Virtual-box Vagrant Puppet Git & Jenkins

VirtualBox is a general-purpose full virtualizer for x86 hardware.

mohammedrafi@NOC-RAFI:~$ vboxmanage –version
4.3.36_Ubuntur105129

Vagrant is an open-source software product for building and maintaining portable virtual software development environments, e.g. for VirtualBox, Hyper-V, Docker, VMware, and AWS.

mohammedrafi@NOC-RAFI:~$ vagrant version
Installed Version: 1.8.1
Latest Version: 1.9.7

To upgrade to the latest version, visit the downloads page and
download and install the latest version of Vagrant from the URL
below:

http://www.vagrantup.com/downloads.html

If you’re curious what changed in the latest release, view the
CHANGELOG below:

https://github.com/mitchellh/vagrant/blob/v1.9.7/CHANGELOG.md

mohammedrafi@NOC-RAFI:~$ mkdir devlopment

mohammedrafi@NOC-RAFI:~$ cd devlopment/

mohammedrafi@NOC-RAFI:~/devlopment$

mohammedrafi@NOC-RAFI:~/devlopment$ vagrant init
A `Vagrantfile` has been placed in this directory. You are now
ready to `vagrant up` your first virtual environment! Please read
the comments in the Vagrantfile as well as documentation on
`vagrantup.com` for more information on using Vagrant.

mohammedrafi@NOC-RAFI:~/devlopment$ ls
Vagrantfile

mohammedrafi@NOC-RAFI:~/devlopment$ cat Vagrantfile
# -*- mode: ruby -*-
# vi: set ft=ruby :

# All Vagrant configuration is done below. The “2” in Vagrant.configure
# configures the configuration version (we support older styles for
# backwards compatibility). Please don’t change it unless you know what
# you’re doing.
Vagrant.configure(2) do |config|
# The most common configuration options are documented and commented below.
# For a complete reference, please see the online documentation at
# https://docs.vagrantup.com.

# Every Vagrant development environment requires a box. You can search for
# boxes at https://atlas.hashicorp.com/search.
config.vm.box = “base”

# Disable automatic box update checking. If you disable this, then
# boxes will only be checked for updates when the user runs
# `vagrant box outdated`. This is not recommended.
# config.vm.box_check_update = false

# Create a forwarded port mapping which allows access to a specific port
# within the machine from a port on the host machine. In the example below,
# accessing “localhost:8080” will access port 80 on the guest machine.
# config.vm.network “forwarded_port”, guest: 80, host: 8080

# Create a private network, which allows host-only access to the machine
# using a specific IP.
# config.vm.network “private_network”, ip: “192.168.33.10”

# Create a public network, which generally matched to bridged network.
# Bridged networks make the machine appear as another physical device on
# your network.
# config.vm.network “public_network”

# Share an additional folder to the guest VM. The first argument is
# the path on the host to the actual folder. The second argument is
# the path on the guest to mount the folder. And the optional third
# argument is a set of non-required options.
# config.vm.synced_folder “../data”, “/vagrant_data”

# Provider-specific configuration so you can fine-tune various
# backing providers for Vagrant. These expose provider-specific options.
# Example for VirtualBox:
#
# config.vm.provider “virtualbox” do |vb|
# # Display the VirtualBox GUI when booting the machine
# vb.gui = true
#
# # Customize the amount of memory on the VM:
# vb.memory = “1024”
# end
#
# View the documentation for the provider you are using for more
# information on available options.

# Define a Vagrant Push strategy for pushing to Atlas. Other push strategies
# such as FTP and Heroku are also available. See the documentation at
# https://docs.vagrantup.com/v2/push/atlas.html for more information.
# config.push.define “atlas” do |push|
# push.app = “YOUR_ATLAS_USERNAME/YOUR_APPLICATION_NAME”
# end

# Enable provisioning with a shell script. Additional provisioners such as
# Puppet, Chef, Ansible, Salt, and Docker are also available. Please see the
# documentation for more information about their specific syntax and use.
# config.vm.provision “shell”, inline: <<-SHELL
# sudo apt-get update
# sudo apt-get install -y apache2
# SHELL
end

mohammedrafi@NOC-RAFI:~/devlopment$ vim Vagrantfile
Vagrant.configure(2) do |config|

### here we are specifying vm provider and vm specifications
config.vm.provider “virtualbox” do |v|
v.memory = 512
v.cpus = 1
end
#### code to spin puppetmaster
### we will be adding identifier to each node say pm,pac,pau that can be any thing
config.vm.define “puppetmaster” do |pm|
pm.vm.box = “centos/7”
pm.vm.network “private_network”, ip: “192.168.33.10”
pm.vm.hostname = “puppetmaster”
end
#### code to spin centos agent
config.vm.define “puppet-agent-centos” do |pac|
pac.vm.box = “centos/7”
pac.vm.network “private_network”, ip: “192.168.33.11”
pac.vm.hostname = “centos-agent”
end
### code to spin ubuntu agent
config.vm.define “puppet-agent-ubuntu” do |pau|
pau.vm.box = “ubuntu/trusty64”
pau.vm.network “private_network”, ip: “192.168.33.12”
pau.vm.hostname = “ubuntu-agent”
end

end

mohammedrafi@NOC-RAFI:~/devlopment$ vagrant status
Current machine states:

puppetmaster not created (virtualbox)
puppet-agent-centos not created (virtualbox)
puppet-agent-ubuntu not created (virtualbox)

This environment represents multiple VMs. The VMs are all listed
above with their current state. For more information about a specific
VM, run `vagrant status NAME`.

mohammedrafi@NOC-RAFI:~/devlopment$ vagrant status puppetmaster
Current machine states:

puppetmaster not created (virtualbox)

The environment has not yet been created. Run `vagrant up` to
create the environment. If a machine is not created, only the
default provider will be shown. So if a provider is not listed,
then the machine is not created for that environment.

mohammedrafi@NOC-RAFI:~/devlopment$ vagrant up
Bringing machine ‘puppetmaster’ up with ‘virtualbox’ provider…
Bringing machine ‘puppet-agent-centos’ up with ‘virtualbox’ provider…
Bringing machine ‘puppet-agent-ubuntu’ up with ‘virtualbox’ provider…
==> puppetmaster: Importing base box ‘centos/7’…
==> puppetmaster: Matching MAC address for NAT networking…
==> puppetmaster: Checking if box ‘centos/7’ is up to date…
==> puppetmaster: A newer version of the box ‘centos/7’ is available! You currently
==> puppetmaster: have version ‘1703.01’. The latest is version ‘1707.01’. Run
==> puppetmaster: `vagrant box update` to update.
==> puppetmaster: Setting the name of the VM: devlopment_puppetmaster_1503405548861_29686
==> puppetmaster: Clearing any previously set network interfaces…
==> puppetmaster: Preparing network interfaces based on configuration…
puppetmaster: Adapter 1: nat
puppetmaster: Adapter 2: hostonly
==> puppetmaster: Forwarding ports…
puppetmaster: 22 (guest) => 2222 (host) (adapter 1)
==> puppetmaster: Running ‘pre-boot’ VM customizations…
==> puppetmaster: Booting VM…
==> puppetmaster: Waiting for machine to boot. This may take a few minutes…
puppetmaster: SSH address: 127.0.0.1:2222
puppetmaster: SSH username: vagrant
puppetmaster: SSH auth method: private key
puppetmaster: Warning: Remote connection disconnect. Retrying…
puppetmaster: Warning: Remote connection disconnect. Retrying…
puppetmaster: Warning: Remote connection disconnect. Retrying…
puppetmaster:
puppetmaster: Vagrant insecure key detected. Vagrant will automatically replace
puppetmaster: this with a newly generated keypair for better security.
puppetmaster:
puppetmaster: Inserting generated public key within guest…
puppetmaster: Removing insecure key from the guest if it’s present…
puppetmaster: Key inserted! Disconnecting and reconnecting using new SSH key…
==> puppetmaster: Machine booted and ready!
==> puppetmaster: Checking for guest additions in VM…
puppetmaster: No guest additions were detected on the base box for this VM! Guest
puppetmaster: additions are required for forwarded ports, shared folders, host only
puppetmaster: networking, and more. If SSH fails on this machine, please install
puppetmaster: the guest additions and repackage the box to continue.
puppetmaster:
puppetmaster: This is not an error message; everything may continue to work properly,
puppetmaster: in which case you may ignore this message.
==> puppetmaster: Setting hostname…
==> puppetmaster: Configuring and enabling network interfaces…
==> puppetmaster: Rsyncing folder: /home/mohammedrafi/devlopment/ => /vagrant
==> puppet-agent-centos: Importing base box ‘centos/7’…
==> puppet-agent-centos: Matching MAC address for NAT networking…
==> puppet-agent-centos: Checking if box ‘centos/7’ is up to date…
==> puppet-agent-centos: A newer version of the box ‘centos/7’ is available! You currently
==> puppet-agent-centos: have version ‘1703.01’. The latest is version ‘1707.01’. Run
==> puppet-agent-centos: `vagrant box update` to update.
==> puppet-agent-centos: Setting the name of the VM: devlopment_puppet-agent-centos_1503405645667_65630
==> puppet-agent-centos: Fixed port collision for 22 => 2222. Now on port 2200.
==> puppet-agent-centos: Clearing any previously set network interfaces…
==> puppet-agent-centos: Preparing network interfaces based on configuration…
puppet-agent-centos: Adapter 1: nat
puppet-agent-centos: Adapter 2: hostonly
==> puppet-agent-centos: Forwarding ports…
puppet-agent-centos: 22 (guest) => 2200 (host) (adapter 1)
==> puppet-agent-centos: Running ‘pre-boot’ VM customizations…
==> puppet-agent-centos: Booting VM…
==> puppet-agent-centos: Waiting for machine to boot. This may take a few minutes…
puppet-agent-centos: SSH address: 127.0.0.1:2200
puppet-agent-centos: SSH username: vagrant
puppet-agent-centos: SSH auth method: private key
puppet-agent-centos: Warning: Remote connection disconnect. Retrying…
puppet-agent-centos: Warning: Remote connection disconnect. Retrying…
puppet-agent-centos: Warning: Remote connection disconnect. Retrying…
puppet-agent-centos:
puppet-agent-centos: Vagrant insecure key detected. Vagrant will automatically replace
puppet-agent-centos: this with a newly generated keypair for better security.
puppet-agent-centos:
puppet-agent-centos: Inserting generated public key within guest…
puppet-agent-centos: Removing insecure key from the guest if it’s present…
puppet-agent-centos: Key inserted! Disconnecting and reconnecting using new SSH key…
==> puppet-agent-centos: Machine booted and ready!
==> puppet-agent-centos: Checking for guest additions in VM…
puppet-agent-centos: No guest additions were detected on the base box for this VM! Guest
puppet-agent-centos: additions are required for forwarded ports, shared folders, host only
puppet-agent-centos: networking, and more. If SSH fails on this machine, please install
puppet-agent-centos: the guest additions and repackage the box to continue.
puppet-agent-centos:
puppet-agent-centos: This is not an error message; everything may continue to work properly,
puppet-agent-centos: in which case you may ignore this message.
==> puppet-agent-centos: Setting hostname…
==> puppet-agent-centos: Configuring and enabling network interfaces…
==> puppet-agent-centos: Rsyncing folder: /home/mohammedrafi/devlopment/ => /vagrant
==> puppet-agent-ubuntu: Box ‘ubuntu/xenial64’ could not be found. Attempting to find and install…
puppet-agent-ubuntu: Box Provider: virtualbox
puppet-agent-ubuntu: Box Version: >= 0
==> puppet-agent-ubuntu: Loading metadata for box ‘ubuntu/xenial64’
puppet-agent-ubuntu: URL: https://atlas.hashicorp.com/ubuntu/xenial64
==> puppet-agent-ubuntu: Adding box ‘ubuntu/xenial64’ (v20170815.1.0) for provider: virtualbox
puppet-agent-ubuntu: Downloading: https://vagrantcloud.com/ubuntu/boxes/xenial64/versions/20170815.1.0/providers/virtualbox.box
==> puppet-agent-ubuntu: Successfully added box ‘ubuntu/xenial64’ (v20170815.1.0) for ‘virtualbox’!
==> puppet-agent-ubuntu: Importing base box ‘ubuntu/xenial64’…
==> puppet-agent-ubuntu: Matching MAC address for NAT networking…
==> puppet-agent-ubuntu: Checking if box ‘ubuntu/xenial64’ is up to date…
==> puppet-agent-ubuntu: Setting the name of the VM: devlopment_puppet-agent-ubuntu_1503405906434_25355
==> puppet-agent-ubuntu: Fixed port collision for 22 => 2222. Now on port 2201.
==> puppet-agent-ubuntu: Clearing any previously set network interfaces…
==> puppet-agent-ubuntu: Preparing network interfaces based on configuration…
puppet-agent-ubuntu: Adapter 1: nat
puppet-agent-ubuntu: Adapter 2: hostonly
==> puppet-agent-ubuntu: Forwarding ports…
puppet-agent-ubuntu: 22 (guest) => 2201 (host) (adapter 1)
==> puppet-agent-ubuntu: Running ‘pre-boot’ VM customizations…
==> puppet-agent-ubuntu: Booting VM…
==> puppet-agent-ubuntu: Waiting for machine to boot. This may take a few minutes…
puppet-agent-ubuntu: SSH address: 127.0.0.1:2201
puppet-agent-ubuntu: SSH username: ubuntu
puppet-agent-ubuntu: SSH auth method: password
puppet-agent-ubuntu: Warning: Remote connection disconnect. Retrying…
puppet-agent-ubuntu:
puppet-agent-ubuntu: Inserting generated public key within guest…
puppet-agent-ubuntu: Removing insecure key from the guest if it’s present…
puppet-agent-ubuntu: Key inserted! Disconnecting and reconnecting using new SSH key…
==> puppet-agent-ubuntu: Machine booted and ready!
==> puppet-agent-ubuntu: Checking for guest additions in VM…
puppet-agent-ubuntu: The guest additions on this VM do not match the installed version of
puppet-agent-ubuntu: VirtualBox! In most cases this is fine, but in rare cases it can
puppet-agent-ubuntu: prevent things such as shared folders from working properly. If you see
puppet-agent-ubuntu: shared folder errors, please make sure the guest additions within the
puppet-agent-ubuntu: virtual machine match the version of VirtualBox you have installed on
puppet-agent-ubuntu: your host and reload your VM.
puppet-agent-ubuntu:
puppet-agent-ubuntu: Guest Additions Version: 5.0.40
puppet-agent-ubuntu: VirtualBox Version: 4.3
==> puppet-agent-ubuntu: Setting hostname…
==> puppet-agent-ubuntu: Configuring and enabling network interfaces…

mohammedrafi@NOC-RAFI:~/devlopment$ vagrant status
Current machine states:

puppetmaster running (virtualbox)
puppet-agent-centos running (virtualbox)
puppet-agent-ubuntu running (virtualbox)

This environment represents multiple VMs. The VMs are all listed
above with their current state. For more information about a specific
VM, run `vagrant status NAME`.

mohammedrafi@NOC-RAFI:~/devlopment$ vagrant ssh
This command requires a specific VM name to target in a multi-VM environment.
mohammedrafi@NOC-RAFI:~/devlopment$ vagrant ssh puppetmaster
[vagrant@puppetmaster ~]$ sudo su –
[root@puppetmaster ~]# cat /etc/redhat-release
CentOS Linux release 7.3.1611 (Core)
[root@puppetmaster ~]# logout
[vagrant@puppetmaster ~]$ logout
Connection to 127.0.0.1 closed.
mohammedrafi@NOC-RAFI:~/devlopment$ vagrant ssh puppet-agent-ubuntu
Welcome to Ubuntu 16.04.3 LTS (GNU/Linux 4.4.0-92-generic x86_64)

* Documentation: https://help.ubuntu.com
* Management: https://landscape.canonical.com
* Support: https://ubuntu.com/advantage

Get cloud support with Ubuntu Advantage Cloud Guest:
http://www.ubuntu.com/business/services/cloud

0 packages can be updated.
0 updates are security updates.

ubuntu@ubuntu-agent:~$ sudo su –
root@ubuntu-agent:~# cat /etc/os-release
NAME=”Ubuntu”
VERSION=”16.04.3 LTS (Xenial Xerus)”
ID=ubuntu
ID_LIKE=debian
PRETTY_NAME=”Ubuntu 16.04.3 LTS”
VERSION_ID=”16.04″
HOME_URL=”http://www.ubuntu.com/&#8221;
SUPPORT_URL=”http://help.ubuntu.com/&#8221;
BUG_REPORT_URL=”http://bugs.launchpad.net/ubuntu/&#8221;
VERSION_CODENAME=xenial
UBUNTU_CODENAME=xenial

mohammedrafi@NOC-RAFI:~/devlopment$ vagrant ssh puppetmaster
Last login: Tue Aug 22 12:51:46 2017 from 10.0.2.2

[vagrant@puppetmaster ~]$ ip a
1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN qlen 1
link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00
inet 127.0.0.1/8 scope host lo
valid_lft forever preferred_lft forever
inet6 ::1/128 scope host
valid_lft forever preferred_lft forever
2: eth0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP qlen 1000
link/ether 52:54:00:88:15:b6 brd ff:ff:ff:ff:ff:ff
inet 10.0.2.15/24 brd 10.0.2.255 scope global dynamic eth0
valid_lft 83388sec preferred_lft 83388sec
inet6 fe80::5054:ff:fe88:15b6/64 scope link
valid_lft forever preferred_lft forever
3: eth1: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP qlen 1000
link/ether 08:00:27:1b:76:87 brd ff:ff:ff:ff:ff:ff
inet 192.168.33.10/24 brd 192.168.33.255 scope global eth1
valid_lft forever preferred_lft forever
inet6 fe80::a00:27ff:fe1b:7687/64 scope link
valid_lft forever preferred_lft forever

mohammedrafi@NOC-RAFI:~/devlopment$ ssh vagrant@192.168.33.10
The authenticity of host ‘192.168.33.10 (192.168.33.10)’ can’t be established.
ECDSA key fingerprint is fb:76:f4:cb:fc:a5:4a:78:b1:6f:c3:c1:b3:10:83:39.
Are you sure you want to continue connecting (yes/no)? yes
Warning: Permanently added ‘192.168.33.10’ (ECDSA) to the list of known hosts.
Permission denied (publickey,gssapi-keyex,gssapi-with-mic).

mohammedrafi@NOC-RAFI:~/devlopment$ ssh -i .vagrant/machines/puppetmaster/virtualbox/private_key vagrant@192.168.33.10
Last login: Tue Aug 22 13:29:34 2017 from 10.0.2.2
[vagrant@puppetmaster ~]$

vagrant1.png

we can use atom as our editor for writing and practising puppet code

https://atom.io/

mohammedrafi@NOC-RAFI:~/devlopment$ sudo add-apt-repository ppa:webupd8team/atom

mohammedrafi@NOC-RAFI:~/devlopment$ sudo apt-get update

mohammedrafi@NOC-RAFI:~/devlopment$ sudo apt-get install atom

mohammedrafi@NOC-RAFI:~/devlopment$ sudo apm install language-puppet
Installing language-puppet to /home/mohammedrafi/.atom/packages âś“

[root@puppetmaster ~]# yum install http://yum.puppetlabs.com/puppetlabs-release-pc1-el-7.noarch.rpm -y
[root@puppetmaster ~]# yum install puppetserver -y

[root@puppetmaster ~]# vim /etc/sysconfig/puppetserver
# Modify this if you’d like to change the memory allocation, enable JMX, etc
#JAVA_ARGS=”-Xms2g -Xmx2g -XX:MaxPermSize=256m”
JAVA_ARGS=”-Xms256m -Xmx256m”

[root@puppetmaster ~]# export PATH={PATH}:/opt/puppetlabs/bin/
[root@puppetmaster ~]# logout
[vagrant@puppetmaster ~]$ sudo -i
[root@puppetmaster ~]# service puppetserver status
Redirecting to /bin/systemctl status puppetserver.service
â—Ź puppetserver.service – puppetserver Service
Loaded: loaded (/usr/lib/systemd/system/puppetserver.service; disabled; vendor preset: disabled)
Active: inactive (dead)

[root@puppetmaster ~]# systemctl start puppetserver

[root@puppetmaster ~]# netstat -tlpn
Active Internet connections (only servers)
Proto Recv-Q Send-Q Local Address Foreign Address State PID/Program name
tcp 0 0 0.0.0.0:111 0.0.0.0:* LISTEN 1/systemd
tcp 0 0 0.0.0.0:22 0.0.0.0:* LISTEN 897/sshd
tcp 0 0 127.0.0.1:25 0.0.0.0:* LISTEN 1634/master
tcp6 0 0 :::8140 :::* LISTEN 32050/java
tcp6 0 0 :::111 :::* LISTEN 1/systemd
tcp6 0 0 :::22 :::* LISTEN 897/sshd
tcp6 0 0 ::1:25 :::* LISTEN 1634/master

[root@puppetmaster ~]# systemctl enable puppetserver
Created symlink from /etc/systemd/system/multi-user.target.wants/puppetserver.service to /usr/lib/systemd/system/puppetserver.service.

[root@puppetmaster ~]# puppetserver –version
puppetserver version: 2.7.2

[root@puppetmaster ~]# ls -l /etc/puppetlabs/code/environments/production/
total 4
-rw-r–r–. 1 root root 879 Aug 8 17:41 environment.conf
drwxr-xr-x. 2 root root 6 Aug 8 17:41 hieradata
drwxr-xr-x. 2 root root 6 Aug 8 17:41 manifests
drwxr-xr-x. 2 root root 6 Aug 8 17:41 modules

[root@puppetmaster ~]# vim /etc/puppetlabs/code/environments/production/manifests/site.pp
node /agent/ {
include webserver
}

[root@puppetmaster ~]# cd /etc/puppetlabs/code/environments/production/modules/

[root@puppetmaster modules]# mkdir -p webserver/manifests

[root@puppetmaster modules]# vim webserver/manifests/init.pp
class webserver {
if $::osfamily == ‘RedHat’ {
package {‘httpd’:
ensure => present
}
} elsif $::osfamily == ‘Debian’ {
package {‘apache2’:
ensure => present
}
}
}

[root@puppetmaster modules]# puppet cert list
[root@puppetmaster modules]# puppet cert list -a
+ “puppetmaster” (SHA256) 70:B1:3B:63:91:AB:0D:A0:C9:03:19:B4:5E:E5:B0:0B:E2:C5:C5:E1:3D:B0:AD:C1:DB:0E:4F:D4:A4:32:42:4D (alt names: “DNS:puppet”, “DNS:puppetmaster”)
######################################

[root@centos-agent ~]# yum install http://yum.puppetlabs.com/puppetlabs-release-pc1-el-7.noarch.rpm -y
[root@centos-agent ~]# yum install puppet-agent -y

[root@centos-agent ~]# export PATH={PATH}:/opt/puppetlabs/bin/
[root@centos-agent ~]# logout
[vagrant@centos-agent ~]$ sudo -i

[root@centos-agent ~]# rpm -qa puppet-agent
puppet-agent-1.10.6-1.el7.x86_64

[root@centos-agent ~]# puppet –version
4.10.6

[root@centos-agent ~]# systemctl enable puppet
Created symlink from /etc/systemd/system/multi-user.target.wants/puppet.service to /usr/lib/systemd/system/puppet.service.

[root@centos-agent ~]# vi /etc/hosts
192.168.33.10 puppetmaster

######################################
root@ubuntu-agent:~# wget http://apt.puppetlabs.com/puppet-release-xenial.deb
root@ubuntu-agent:~# dpkg -i puppet-release-xenial.deb

root@ubuntu-agent:~# apt-get install puppet -y
root@ubuntu-agent:~# apt-get install puppet-agent -y

root@ubuntu-agent:~# export PATH={PATH}:/opt/puppetlabs/bin/
root@ubuntu-agent:~# logout
ubuntu@ubuntu-agent:~$ sudo -i

root@ubuntu-agent:~# systemctl enable puppet

root@ubuntu-agent:~# vim /etc/hosts
192.168.33.10 puppetmaster
#####################################
[root@centos-agent ~]# puppet agent -t –server puppetmaster
Info: Creating a new SSL key for centos-agent
Info: Caching certificate for ca
Info: csr_attributes file loading from /etc/puppetlabs/puppet/csr_attributes.yaml
Info: Creating a new SSL certificate request for centos-agent
Info: Certificate Request fingerprint (SHA256): 0E:A2:87:34:09:CF:0C:9A:7C:57:29:D4:F1:62:94:54:13:34:F9:83:12:8E:86:DB:D8:39:2E:46:B0:39:EB:FB
Info: Caching certificate for ca
Exiting; no certificate found and waitforcert is disabled

root@ubuntu-agent:~# puppet agent -t –server puppetmaster
Info: Creating a new SSL key for ubuntu-agent
Warning: Downgrading to PSON for future requests
Info: Caching certificate for ca
Info: csr_attributes file loading from /etc/puppetlabs/puppet/csr_attributes.yaml
Info: Creating a new SSL certificate request for ubuntu-agent
Info: Certificate Request fingerprint (SHA256): 03:F0:61:25:CC:07:AC:BF:A8:B7:7D:2B:C6:B4:EB:0E:42:95:24:EF:3E:0A:76:EC:58:89:7A:47:CE:31:29:27
Info: Caching certificate for ca
Exiting; no certificate found and waitforcert is disabled

[root@puppetmaster modules]# puppet cert list
“centos-agent” (SHA256) 0E:A2:87:34:09:CF:0C:9A:7C:57:29:D4:F1:62:94:54:13:34:F9:83:12:8E:86:DB:D8:39:2E:46:B0:39:EB:FB
“ubuntu-agent” (SHA256) 03:F0:61:25:CC:07:AC:BF:A8:B7:7D:2B:C6:B4:EB:0E:42:95:24:EF:3E:0A:76:EC:58:89:7A:47:CE:31:29:27

[root@puppetmaster modules]# puppet cert sign centos-agent
Signing Certificate Request for:
“centos-agent” (SHA256) 0E:A2:87:34:09:CF:0C:9A:7C:57:29:D4:F1:62:94:54:13:34:F9:83:12:8E:86:DB:D8:39:2E:46:B0:39:EB:FB
Notice: Signed certificate request for centos-agent
Notice: Removing file Puppet::SSL::CertificateRequest centos-agent at ‘/etc/puppetlabs/puppet/ssl/ca/requests/centos-agent.pem’

[root@puppetmaster modules]# puppet cert sign ubuntu-agent
Signing Certificate Request for:
“ubuntu-agent” (SHA256) 03:F0:61:25:CC:07:AC:BF:A8:B7:7D:2B:C6:B4:EB:0E:42:95:24:EF:3E:0A:76:EC:58:89:7A:47:CE:31:29:27
Notice: Signed certificate request for ubuntu-agent
Notice: Removing file Puppet::SSL::CertificateRequest ubuntu-agent at ‘/etc/puppetlabs/puppet/ssl/ca/requests/ubuntu-agent.pem’

[root@centos-agent ~]# puppet agent -t –server puppetmaster
Info: Using configured environment ‘production’
Info: Retrieving pluginfacts
Info: Retrieving plugin
Info: Caching catalog for centos-agent
Info: Applying configuration version ‘1503415543’
Notice: /Stage[main]/Webserver/Package[httpd]/ensure: created
Info: Creating state file /opt/puppetlabs/puppet/cache/state/state.yaml
Notice: Applied catalog in 23.76 seconds

root@ubuntu-agent:~# puppet agent -t –server puppetmaster
Warning: Downgrading to PSON for future requests
Info: Using configured environment ‘production’
Info: Retrieving pluginfacts
Info: Retrieving plugin
Info: Caching catalog for ubuntu-agent
Info: Applying configuration version ‘1503415538’
Notice: /Stage[main]/Webserver/Package[apache2]/ensure: created
Info: Creating state file /opt/puppetlabs/puppet/cache/state/state.yaml
Notice: Applied catalog in 34.80 seconds

######################################

[root@puppetmaster ~]# cd /etc/puppetlabs/code/environments/production/

[root@puppetmaster production]# mkdir -p modules/webserver/templates/

[root@puppetmaster production]# vim modules/webserver/templates/vhost.conf.erb

<VirtualHost *:80>
ServerName <%= @fqdn %>
DocumentRoot /var/www/html
</VirtualHost>

[root@puppetmaster production]# mkdir modules/webserver/files
[root@puppetmaster production]# vim modules/webserver/files/httpd.conf
ServerRoot “/etc/httpd”
Listen 80
Include conf.modules.d/*.conf
User apache
Group apache
ServerAdmin root@localhost

AllowOverride none
Require all denied

DocumentRoot “/var/www/html”
<Directory “/var/www”>
AllowOverride None
# Allow open access:
Require all granted

<Directory “/var/www/html”>
Options Indexes FollowSymLinks
AllowOverride None
Require all granted

DirectoryIndex index.html

<Files “.ht*”>
Require all denied

ErrorLog “logs/error_log”
LogLevel warn

LogFormat “%h %l %u %t \”%r\” %>s %b \”%{Referer}i\” \”%{User-Agent}i\”” combined
LogFormat “%h %l %u %t \”%r\” %>s %b” common

LogFormat “%h %l %u %t \”%r\” %>s %b \”%{Referer}i\” \”%{User-Agent}i\” %I %O” combinedio

CustomLog “logs/access_log” combined

ScriptAlias /cgi-bin/ “/var/www/cgi-bin/”

<Directory “/var/www/cgi-bin”>
AllowOverride None
Options None
Require all granted

TypesConfig /etc/mime.types
AddType application/x-compress .Z
AddType application/x-gzip .gz .tgz
AddType text/html .shtml
AddOutputFilter INCLUDES .shtml

AddDefaultCharset UTF-8

MIMEMagicFile conf/magic

IncludeOptional conf.d/*.conf
###############################

[root@centos-agent ~]# yum remove httpd -y
[root@centos-agent ~]# puppet agent -t –server puppetmaster
Info: Using configured environment ‘production’
Info: Retrieving pluginfacts
Info: Retrieving plugin
Info: Caching catalog for centos-agent
Info: Applying configuration version ‘1503447096’
Notice: /Stage[main]/Webserver/Package[httpd]/ensure: created
Notice: /Stage[main]/Webserver/File[/etc/httpd/conf/httpd.conf]/content:
— /etc/httpd/conf/httpd.conf 2017-04-12 13:50:43.000000000 +0000
+++ /tmp/puppet-file20170823-4574-19cdll 2017-08-23 00:13:24.445137241 +0000
@@ -1,4 +1,3 @@
-#
# This is the main Apache HTTP server configuration file. It contains the
# configuration directives that give the server its instructions.
# See <URL:http://httpd.apache.org/docs/2.4/&gt; for detailed information.
@@ -351,3 +350,4 @@
#
# Load config files in the “/etc/httpd/conf.d” directory, if any.
IncludeOptional conf.d/*.conf
+

Info: Computing checksum on file /etc/httpd/conf/httpd.conf
Info: FileBucket got a duplicate file {md5}f5e7449c0f17bc856e86011cb5d152ba
Info: /Stage[main]/Webserver/File[/etc/httpd/conf/httpd.conf]: Filebucketed /etc/httpd/conf/httpd.conf to puppet with sum f5e7449c0f17bc856e86011cb5d152ba
Notice: /Stage[main]/Webserver/File[/etc/httpd/conf/httpd.conf]/content:

Notice: /Stage[main]/Webserver/File[/etc/httpd/conf/httpd.conf]/content: content changed ‘{md5}f5e7449c0f17bc856e86011cb5d152ba’ to ‘{md5}3ab4d8f211c9355f085fc214540c7c57’
Notice: /Stage[main]/Webserver/File[/etc/httpd/conf.d/vhost.conf]/ensure: defined content as ‘{md5}f42293aee75b01ae565dcf9e41d7bb11’
Notice: /Stage[main]/Webserver/Service[httpd]/ensure: ensure changed ‘stopped’ to ‘running’
Info: /Stage[main]/Webserver/Service[httpd]: Unscheduling refresh on Service[httpd]
Notice: Applied catalog in 107.18 seconds

[root@centos-agent ~]# service httpd status
Redirecting to /bin/systemctl status httpd.service
â—Ź httpd.service – The Apache HTTP Server
Loaded: loaded (/usr/lib/systemd/system/httpd.service; enabled; vendor preset: disabled)
Active: active (running) since Wed 2017-08-23 00:13:24 UTC; 38s ago

[root@centos-agent ~]# yum remove httpd -y

[root@puppetmaster production]# vim modules/webserver/manifests/parameters.pp
class webserver::parameters {
if $::osfamily == ‘RedHat’ {
$packagename = ‘httpd’
$configfile = ‘/etc/httpd/conf/httpd.conf’
$configsource = ‘puppet:///modules/webserver/httpd.conf’
$vhostfile = ‘/etc/httpd/conf.d/vhost.conf’
} elsif $::osfamily == ‘Debian’ {
$packagename = ‘apache2’
$configfile = ‘/etc/apache2/apache2.conf’
$configsource = ‘puppet:///modules/webserver/apache2.conf’
$vhostfile = ‘/etc/apache2/sites-enabled/vhost.conf’
}
}

[root@puppetmaster production]# puppet parser validate modules/webserver/manifests/parameters.pp

[root@puppetmaster production]# vim modules/webserver/manifests/init.pp
class webserver (
$packagename = $::webserver::parameters::packagename,
$configfile = $::webserver::parameters::configfile,
$configsource = $::webserver::parameters::configsource,
$vhostfile = $::webserver::parameters::vhostfile,
)inherits ::webserver::parameters {
package {‘webserver-package’:
name => $packagename,
ensure => present
}

file {‘config-file’:
path => $configfile,
ensure => file,
source => $configsource,
require => Package[‘webserver-package’],
notify => Service[‘webserver-service’],
}

file {‘vhost-file’:
path => $vhostfile,
ensure => file,
content => template(‘webserver/vhost.conf.erb’),
require => Package[‘webserver-package’],
notify => Service[‘webserver-service’],
}

service {‘webserver-service’:
name => $packagename,
ensure => running,
enable => true,
hasrestart => true,
require => [File[‘config-file’],File[‘vhost-file’]],
subscribe => [File[‘config-file’],File[‘vhost-file’]],
}
}

[root@puppetmaster production]# puppet parser validate modules/webserver/manifests/init.pp

[root@centos-agent ~]# puppet agent -t –server puppetmaster
Info: Using configured environment ‘production’
Info: Retrieving pluginfacts
Info: Retrieving plugin
Info: Caching catalog for centos-agent
Info: Applying configuration version ‘1503449187’
Notice: /Stage[main]/Webserver/Package[webserver-package]/ensure: created
Notice: /Stage[main]/Webserver/File[config-file]/content:
— /etc/httpd/conf/httpd.conf 2017-04-12 13:50:43.000000000 +0000
+++ /tmp/puppet-file20170823-4931-1cfvji 2017-08-23 00:46:43.853418390 +0000
@@ -1,4 +1,3 @@
-#
# This is the main Apache HTTP server configuration file. It contains the
# configuration directives that give the server its instructions.
# See <URL:http://httpd.apache.org/docs/2.4/&gt; for detailed information.
@@ -351,3 +350,4 @@
#
# Load config files in the “/etc/httpd/conf.d” directory, if any.
IncludeOptional conf.d/*.conf
+

Info: Computing checksum on file /etc/httpd/conf/httpd.conf
Info: FileBucket got a duplicate file {md5}f5e7449c0f17bc856e86011cb5d152ba
Info: /Stage[main]/Webserver/File[config-file]: Filebucketed /etc/httpd/conf/httpd.conf to puppet with sum f5e7449c0f17bc856e86011cb5d152ba
Notice: /Stage[main]/Webserver/File[config-file]/content: content changed ‘{md5}f5e7449c0f17bc856e86011cb5d152ba’ to ‘{md5}3ab4d8f211c9355f085fc214540c7c57’
Info: /Stage[main]/Webserver/File[config-file]: Scheduling refresh of Service[webserver-service]
Info: /Stage[main]/Webserver/File[config-file]: Scheduling refresh of Service[webserver-service]
Notice: /Stage[main]/Webserver/File[vhost-file]/ensure: defined content as ‘{md5}f42293aee75b01ae565dcf9e41d7bb11’
Info: /Stage[main]/Webserver/File[vhost-file]: Scheduling refresh of Service[webserver-service]
Info: /Stage[main]/Webserver/File[vhost-file]: Scheduling refresh of Service[webserver-service]
Notice: /Stage[main]/Webserver/Service[webserver-service]/ensure: ensure changed ‘stopped’ to ‘running’
Info: /Stage[main]/Webserver/Service[webserver-service]: Unscheduling refresh on Service[webserver-service]
Notice: Applied catalog in 14.82 seconds

[root@centos-agent ~]# service httpd status
Redirecting to /bin/systemctl status httpd.service
â—Ź httpd.service – The Apache HTTP Server
Loaded: loaded (/usr/lib/systemd/system/httpd.service; enabled; vendor preset: disabled)
Active: active (running) since Wed 2017-08-23 00:46:44 UTC; 45s ago

root@ubuntu-agent:~# puppet agent -t –server puppetmaster

Warning: Downgrading to PSON for future requests
Info: Caching certificate for ubuntu-agent
Info: Caching certificate_revocation_list for ca
Info: Caching certificate for ubuntu-agent
Info: Using configured environment ‘production’
Info: Retrieving pluginfacts
Info: Retrieving plugin
Info: Caching catalog for ubuntu-agent
Info: Applying configuration version ‘1503454992’
Notice: /Stage[main]/Webserver/Package[webserver-package]/ensure: created
Notice: /Stage[main]/Webserver/File[vhost-file]/ensure: defined content as ‘{md5}d51395b65b5a2a161dc51cb17d0720b2’
Info: /Stage[main]/Webserver/File[vhost-file]: Scheduling refresh of Service[webserver-service]
Info: /Stage[main]/Webserver/File[vhost-file]: Scheduling refresh of Service[webserver-service]
Notice: /Stage[main]/Webserver/Service[webserver-service]: Triggered ‘refresh’ from 2 events
Info: Creating state file /opt/puppetlabs/puppet/cache/state/state.yaml
Notice: Applied catalog in 21.95 seconds

root@ubuntu-agent:~# service apache2 status
* apache2 is running

mohammedrafi@NOC-RAFI:~/devlopment$ vagrant halt
==> puppet-agent-ubuntu: Attempting graceful shutdown of VM…
==> puppet-agent-centos: Attempting graceful shutdown of VM…
==> puppetmaster: Attempting graceful shutdown of VM…
==> puppetmaster: Forcing shutdown of VM…

 

Leave a comment