This is a work in progress...

Creating a Puppet Master Server

For this Instruction I am using 2 Virtual Machines on Ubuntu 16.04 LTS

wget https://apt.puppetlabs.com/puppetlabs-release-pc1-xenial.deb
sudo dpkg -i puppetlabs-release-pc1-xenial.deb
sudo apt-get update
sudo apt-get install puppetserver

Modifying the Memory Limit on Puppet Master

Puppet default memory use is 2GB edit the puppetserver file to change it to 512mb.

sudo vi /etc/default/puppetserver

Adjust the line

# Modify this if you'd like to change the memory allocation, enable JMX, etc
JAVA_ARGS="-Xms2g -Xmx2g -XX:MaxPermSize=256m"

to

# Modify this if you'd like to change the memory allocation, enable JMX, etc
JAVA_ARGS="-Xms512m -Xmx512m -XX:MaxPermSize=256m"

Defining the DNS for the Server

For the Puppet Agents to find the Puppet Master server the DNS needs to be defined in the configuration file.

sudo vi /etc/puppetlabs/puppet/puppet.conf

Add this to the end of the file since our server ip is 192.168.237.130 we will use this in our example.

dns_alt_names = hostname,192.168.237.130
[main]
certname = 192.168.237.130
server = 192.168.237.130
environment = production
runinterval = 5m

Start the Puppet Server and Enable Start on Reboot

sudo /opt/puppetlabs/bin/puppet resource service puppet ensure=running enable=true

Should be followed by

Notice: /Service[puppet]/ensure: ensure changed 'stopped' to 'running'
service { 'puppet':
 ensure => 'running',
 enable => 'true',
}

Creating the Puppet Agent Node

wget https://apt.puppetlabs.com/puppetlabs-release-pc1-xenial.deb
sudo dpkg -i puppetlabs-release-pc1-xenial.deb
sudo apt-get update
sudo apt-get install puppet-agent

Configuring the Config File to Find the Puppet Master Server

sudo vi /etc/puppetlabs/puppet/puppet.conf


[main]
certname = puppetagent3
server = 192.168.237.130
environment = production
runinterval = 20m


How to Execute Puppet Scripts

sudo puppet apply "puppet script"

Updating Ubuntu

exec { 'apt-update': # exec resource named 'apt-update'
command => '/usr/bin/apt-get update' # command this resource will run
}

Installing Apache2

package { 'apache2':
require => Exec['apt-update'], # require 'apt-update' before installing
ensure => installed,
}

Ensuring Apache2 is running

service { 'apache2':
ensure => running,
}

Creating a Group and Assigning a GID

group { 'serveradmin':
ensure => 'present',
gid => '3000',
}

Creating a User

user { 'serveradmin':
ensure => 'present',
managehome => 'true',
home => '/home/serveradmin',
comment => 'Server Admin',
groups => 'serveradmin',
password => 'serveradmin',
password_max_age => '99999',
password_min_age => '0',
shell => '/bin/bash',
uid => '3000',
}

Installing a Database

# install postgresql package
package { 'postgresql':
require => Exec['apt-update'], # require 'apt-update' before installing
ensure => installed,
}

# ensure postgresql service is running
service { 'postgresql':
ensure => running,
}

Creating a Database Instance

class { 'postgresql::server': }

postgresql::server::db { 'testdb':
user => 'admin',
password => postgresql_password('admin', 'c00kies'),
owner => 'admin',
}

class mymodule::myclass{
file { 'my_bash_script':
ensure => 'file',
path => '/home/setupadmin/runthisfile.sh',
owner => 'setupadmin',
group => 'setupadmin',
mode => '0755', # Use 0700 if it is sensitive
notify => Exec['run_my_script'],
}
exec { 'run_my_script':
#path => ["/usr/bin", "/usr/sbin", "/bin/bash"],
command => '/home/setupadmin/runthisfile.sh',
refreshonly => true
}
}
include mymodule::myclass