Building Puppet 4.0 test environment with Vagrant

Puppet 4.0 RC is released

Here’s some notes how to build CentOS/vagrant/puppet master and agent and some relevant links

Release notes

https://puppetlabs.com/blog/release-candidate-open-source-puppet-4.0

https://groups.google.com/forum/#!msg/puppet-announce/Wl9Ag2gRmXM/RpdggribgvwJ

Prerequisities for test environment

VirtualBox

Grab and install VirtualBox https://www.virtualbox.org/wiki/Downloads

Vagrant

Grab and install Vagrant https://www.vagrantup.com/downloads.html

CentOS

Get minimal install ISO from suitable mirror http://isoredirect.centos.org/centos/7/isos/x86_64/

Building puppet server and agent vagrant base boxes

Vagrant base box creation

Create new virtual machines in VirtualBox

One vm for server and one for agent is needed

  • keep ’em lean
    • no audio
    • no USB controller
    • dynamically allocated disk
    • puppetserver needs at least 1,4 GB of memory
  • network adapter 1 in NAT mode

Install CentOS to server and agent

Start virtual machine, select downloaded CentOS ISO as boot media and install CentOS

  • activate network interface
    • server hostname puppetserver.dev
    • agent hostname puppetagent-centos.dev
  • set root password to vagrant
  • add user vagrant
    • password vagrant
    • tick ‘Make this use administrator’

Configure CentOS installation for vagrant

Login and update installation(s) with ‘yum update‘ and reboot.

It seems that puppet server just loves to bind to IPv6 in CentOS, hence disable it on server vm http://wiki.centos.org/FAQ/CentOS7#head-8984faf811faccca74c7bcdd74de7467f2fcd8ee

Edit /etc/default/grub GRUB_TIMEOUT=5 => 1 and execute ‘grub2-mkconfig -o /boot/grub2/grub.cfg

Disable and stop firewalld ‘systemctl disable firewalld‘ ‘systemctl stop firewalld

Go through ‘Vagrant base box’ and VirtualBox specifics below

Vagrant base box

https://docs.vagrantup.com/v2/boxes/base.html

VirtualBox specifics

https://docs.vagrantup.com/v2/virtualbox/boxes.html

Installing VirtualBox Guest Additions on CentOS

http://wiki.centos.org/HowTos/Virtualization/VirtualBox/CentOSguest

  • yum install epel-release
  • (yum update)
  • yum install dkms
  • yum groupinstall “Development Tools”
  • yum install kernel-devel
  • VirtualBox -> Devices -> Install Guest Additions CD image…
  • mount CD to directory
  • cd to mounted directory and run VBoxLinuxAdditions.run
  • reboot

Install puppet master and agent

Please note that some steps might be missing, do go through installation guides

Puppet master

Puppet agent

Create base boxes

vagrant package –base puppetmaster4 –output puppetmaster4-centos.box puppetmaster4
vagrant package –base puppetagent4-centos –output puppetagent4-centos.box puppetagent4-centos

Copy boxes to webserver

Vagrantfile

# -*- mode: ruby -*-
# vi: set ft=ruby :

# Vagrantfile API/syntax version. Don't touch unless you know what you're doing!
VAGRANTFILE_API_VERSION = "2"

Vagrant.configure(VAGRANTFILE_API_VERSION) do |config|
  # Allow symlinks in host
  config.vm.provider "virtualbox" do |v|
    v.customize ["setextradata", :id, "VBoxInternal2/SharedFoldersEnableSymlinksCreate/v-root", "1"]
  end
  # puppetmaster config
  config.vm.define "pm4-centos7" do |puppetmaster|
    puppetmaster.vm.box = "puppetmaster4-centos"
    puppetmaster.vm.box_url = "http://yourserver/puppetmaster4-centos.box"
    ## 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.
    puppetmaster.vm.network "forwarded_port", guest: 8140, host: 8140
    ## Create a private network, which allows host-only access to the machine
    ## using a specific IP.
    puppetmaster.vm.network "private_network", ip: "10.254.254.2"
    # Add public network also, uses dhcp
    puppetmaster.vm.network "public_network"
    # Sync puppet codebase
    puppetmaster.vm.synced_folder 'puppet/', '/etc/puppetlabs/environments/production/', owner: 'puppet', group: 'puppet'
  end

  # puppet agent
  config.vm.define "pa4-centos7" do |centos7|
    centos7.vm.box = "puppetagent4-centos"
    centos7.vm.box_url = "http://yourserver/puppetagent4-centos.box"
    centos7.vm.network "private_network", ip: "10.254.254.3"
    # Add public network also, uses dhcp 
    centos7.vm.network "public_network"
  end
end

Run

cd / make new work directory, place above Vagrantfile there (edit box location), create subdirectory puppet where you can clone your current puppet code git repository

vagrant up‘ to start master and agent, vagrant will ask to which interface public network is to be binded

ssh to master/agent with ‘vagrant ssh pm4-centos7‘ / ‘vagrant ssh pa4-centos7

vagrant halt to shutdown master and agent

Example site.pp

Put following to host vagrant_work_dir/puppet/manifests/site.pp

notify { 'test' :
 message => 'Jepjep, it works',
}

Example run

$ vagrant up
Bringing machine 'pm4-centos7' up with 'virtualbox' provider...
Bringing machine 'pa4-centos7' up with 'virtualbox' provider...
==> pm4-centos7: Clearing any previously set forwarded ports...
==> pm4-centos7: Clearing any previously set network interfaces...
==> pm4-centos7: Available bridged network interfaces:
1) en1: Wi-Fi (AirPort)
2) en0: Ethernet
3) en2: Thunderbolt 1
4) bridge0
5) p2p0
==> pm4-centos7: When choosing an interface, it is usually the one that is
==> pm4-centos7: being used to connect to the internet.
 pm4-centos7: Which interface should the network bridge to? 1
==> pm4-centos7: Preparing network interfaces based on configuration...
 pm4-centos7: Adapter 1: nat
 pm4-centos7: Adapter 2: hostonly
 pm4-centos7: Adapter 3: bridged
==> pm4-centos7: Forwarding ports...
 pm4-centos7: 8140 => 8140 (adapter 1)
 pm4-centos7: 22 => 2222 (adapter 1)
==> pm4-centos7: Running 'pre-boot' VM customizations...
==> pm4-centos7: Booting VM...
==> pm4-centos7: Waiting for machine to boot. This may take a few minutes...
 pm4-centos7: SSH address: 127.0.0.1:2222
 pm4-centos7: SSH username: vagrant
 pm4-centos7: SSH auth method: private key
 pm4-centos7: Warning: Connection timeout. Retrying...
==> pm4-centos7: Machine booted and ready!
==> pm4-centos7: Checking for guest additions in VM...
==> pm4-centos7: Configuring and enabling network interfaces...
==> pm4-centos7: Mounting shared folders...
 pm4-centos7: /vagrant => /xxx/yyy/virtual/vagrant/puppet4
 pm4-centos7: /etc/puppetlabs/code/environments/production => /xxx/yyy/virtual/vagrant/puppet4/puppet
==> pm4-centos7: Machine already provisioned. Run `vagrant provision` or use the `--provision`
==> pm4-centos7: to force provisioning. Provisioners marked to run always will still run.
==> pa4-centos7: Clearing any previously set forwarded ports...
==> pa4-centos7: Fixed port collision for 22 => 2222. Now on port 2200.
==> pa4-centos7: Clearing any previously set network interfaces...
==> pa4-centos7: Available bridged network interfaces:
1) en1: Wi-Fi (AirPort)
2) en0: Ethernet
3) en2: Thunderbolt 1
4) bridge0
5) p2p0
==> pa4-centos7: When choosing an interface, it is usually the one that is
==> pa4-centos7: being used to connect to the internet.
 pa4-centos7: Which interface should the network bridge to? 1
==> pa4-centos7: Preparing network interfaces based on configuration...
 pa4-centos7: Adapter 1: nat
 pa4-centos7: Adapter 2: hostonly
 pa4-centos7: Adapter 3: bridged
==> pa4-centos7: Forwarding ports...
 pa4-centos7: 22 => 2200 (adapter 1)
==> pa4-centos7: Running 'pre-boot' VM customizations...
==> pa4-centos7: Booting VM...
==> pa4-centos7: Waiting for machine to boot. This may take a few minutes...
 pa4-centos7: SSH address: 127.0.0.1:2200
 pa4-centos7: SSH username: vagrant
 pa4-centos7: SSH auth method: private key
 pa4-centos7: Warning: Connection timeout. Retrying...
==> pa4-centos7: Machine booted and ready!
==> pa4-centos7: Checking for guest additions in VM...
==> pa4-centos7: Configuring and enabling network interfaces...
==> pa4-centos7: Mounting shared folders...
 pa4-centos7: /vagrant => /xxx/yyy/virtual/vagrant/puppet4
==> pa4-centos7: Machine already provisioned. Run `vagrant provision` or use the `--provision`
==> pa4-centos7: to force provisioning. Provisioners marked to run always will still run.
$ vagrant ssh pa4-centos7
Last login: Mon Mar 23 17:45:39 2015 from 10.0.2.2
-bash: warning: setlocale: LC_CTYPE: cannot change locale (UTF-8): No such file or directory
[vagrant@puppetagent-centos ~]$ sudo su -
Last login: Mon Mar 23 17:45:43 EET 2015 on pts/0
[root@puppetagent-centos ~]# /opt/puppetlabs/bin/puppet agent -t
Info: Retrieving pluginfacts
Info: Retrieving plugin
Info: Caching catalog for puppetagent-centos.dev
Info: Applying configuration version '1427126268'
Notice: Jepjep, it works
Notice: /Stage[main]/Main/Notify[testtest]/message: defined 'message' as 'Jepjep, it works'
Notice: Applied catalog in 0.02 seconds
[root@puppetagent-centos ~]# exit
logout
[vagrant@puppetagent-centos ~]$ exit
logout
Connection to 127.0.0.1 closed.
$ vagrant halt
==> pa4-centos7: Attempting graceful shutdown of VM...
==> pm4-centos7: Attempting graceful shutdown of VM...

Leave a Reply

Your email address will not be published. Required fields are marked *