-
Notifications
You must be signed in to change notification settings - Fork 29
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
23 changed files
with
195 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
.vagrant | ||
logs/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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" | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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', | ||
} | ||
} | ||
|
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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", | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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" | ||
} | ||
] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
5 changes: 5 additions & 0 deletions
5
vagrant/puppet/legacy/part2_centos/site/hello_web/files/index.html
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
<html> | ||
<body> | ||
<h1>Hello World!</h1> | ||
</body> | ||
</html> |
File renamed without changes.