Skip to content

Commit

Permalink
Puppet 8 update (#51)
Browse files Browse the repository at this point in the history
  • Loading branch information
darkn3rd authored Oct 9, 2024
1 parent 691c390 commit 8cea009
Show file tree
Hide file tree
Showing 23 changed files with 195 additions and 0 deletions.
2 changes: 2 additions & 0 deletions vagrant/puppet/hello_web/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
.vagrant
logs/
76 changes: 76 additions & 0 deletions vagrant/puppet/hello_web/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
# Puppet Introduction

This tutorial covers how to get started with Puppet using Vagrant for automation some basic modules of your design.

# Directory Structure

You can create a similar directory structure with the following commands:

```bash
# craete directory structure
mkdir -p site/hello_web/{manifests,files} {ubuntu2204,rocky9}/manifests
# create files
touch \
bootstrap.sh \
site/hello_web/{manifests/init.pp,files/index.html,metadata.json} \
{ubuntu2204,rocky9}/{manifests/default.pp,Vagrantfile}
```

This should create:

```
.
├── bootstrap.sh
├── rocky9
│   ├── Vagrantfile
│   └── manifests
│   └── default.pp
├── site
│   └── hello_web
│   ├── files
│   │   └── index.html
│   ├── manifests
│   │   └── init.pp
│   └── metadata.json
└── ubuntu2204
├── Vagrantfile
└── manifests
└── default.pp
```

# Provisioning the System

To get started, navigate to the appropriate distro directory, i.e. `rocky9` or `ubuntu2204`, and run `vagrant up`. This will do the following:


1. Create a virtual machine, e.g. memory, vcpu, hard disk, etc.
2. Download the VM image, e.g. Rocky 9 or Ubuntu 22.04 "Jammy"
3. Start the virtual machine
4. Provision the system with shell, which installs puppet agent
5. Provision the system with Puppet

```bash
vagrant up
```

# Provisioning Manually

Alternatively, you can run this manually from within the virtual machine. You would run this.

```shell
vagrant up --no-provision
vagrant provision --provision-with "bootstrap" # install puppet agent
vagrant ssh # log into VM
```

Then once inside the virtual machine guest, you can run the following commands:

```bash
# Inside VM
MODULES=$(mount | grep -o '/tmp/vagrant-puppet/modules-[^ ]*')
MANIFESTS=$(mount | grep -o '/tmp/vagrant-puppet/manifests-[^ ]*' | uniq)
puppet apply --verbose --debug \
--modulepath "$MODULES:/etc/puppet/modules" \
--detailed-exitcodes \
"$MANIFESTS/default.pp"
```
22 changes: 22 additions & 0 deletions vagrant/puppet/hello_web/bootstrap.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
#!/bin/sh
command -v puppet > /dev/null && { echo "Puppet is installed! skipping" ; exit 0; }

ID=$(grep -oP '(?<=^ID=).*' /etc/os-release | tr -d '"')

case "${ID}" in
rocky)
VERS=$(grep -oP '(?<=PLATFORM_ID="platform:el).*[0-9]' /etc/os-release)
sudo rpm -Uvh https://yum.puppet.com/puppet8-release-el-${VERS}.noarch.rpm
sudo yum install -y puppet-agent
;;
debian|ubuntu)
wget https://apt.puppetlabs.com/puppet8-release-$(lsb_release -cs).deb
sudo dpkg -i puppet8-release-$(lsb_release -cs).deb
sudo apt-get -qq update
sudo apt-get install -y puppet-agent
;;
*)
echo "ERROR: Distro '${ID}' not supported" 2>&1
exit 1
;;
esac
14 changes: 14 additions & 0 deletions vagrant/puppet/hello_web/rocky9/Vagrantfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
Vagrant.configure("2") do |config|
config.vm.box = "generic/rocky9"
config.vm.network "forwarded_port", guest: 80, host: 8083

####### Install Puppet Agent #######
config.vm.provision "bootstrap", before: :all, type: "shell", path: "../bootstrap.sh"

####### Provision #######
config.vm.provision :puppet do |puppet|
puppet.module_path = "../site"
puppet.options = "--verbose --debug"
end
end

8 changes: 8 additions & 0 deletions vagrant/puppet/hello_web/rocky9/manifests/default.pp
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
node default {
class { 'hello_web':
package_name => 'httpd',
service_name => 'httpd',
doc_root => '/var/www/html',
}
}

19 changes: 19 additions & 0 deletions vagrant/puppet/hello_web/site/hello_web/manifests/init.pp
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
class hello_web (
$package_name = 'apache2',
$service_name = 'apache2',
$doc_root = '/var/www/html'
) {

package { $package_name:
ensure => present,
}

service { $service_name:
ensure => running,
enable => true,
}

file { "$doc_root/index.html":
source => "puppet:///modules/hello_web/index.html",
}
}
33 changes: 33 additions & 0 deletions vagrant/puppet/hello_web/site/hello_web/metadata.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
{
"name": "joachim8675309-hello_web",
"version": "0.1.0",
"author": "joachim8675309",
"summary": "Hello World Tutorial",
"license": "Apache-2.0",
"source": "https://github.com/darkn3rd/blog_tutorials",
"dependencies": [],
"operatingsystem_support": [
{
"operatingsystem": "RedHat",
"operatingsystemrelease": ["9"]
},
{
"operatingsystem": "Rocky",
"operatingsystemrelease": ["9"]
},
{
"operatingsystem": "Debian",
"operatingsystemrelease": ["12"]
},
{
"operatingsystem": "Ubuntu",
"operatingsystemrelease": ["22.04"]
}
],
"requirements": [
{
"name": "puppet",
"version_requirement": ">= 7.24 < 9.0.0"
}
]
}
13 changes: 13 additions & 0 deletions vagrant/puppet/hello_web/ubuntu2204/Vagrantfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
Vagrant.configure('2') do |config|
config.vm.box = 'generic/ubuntu2204'
config.vm.network 'forwarded_port', guest: 80, host: 8085

####### Install Puppet Agent #######
config.vm.provision "bootstrap", before: :all, type: "shell", path: "../bootstrap.sh"

####### Provision #######
config.vm.provision :puppet do |puppet|
puppet.module_path = "../site"
puppet.options = "--verbose --debug"
end
end
3 changes: 3 additions & 0 deletions vagrant/puppet/hello_web/ubuntu2204/manifests/default.pp
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
node default {
class { 'hello_web': }
}
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
<html>
<body>
<h1>Hello World!</h1>
</body>
</html>

0 comments on commit 8cea009

Please sign in to comment.