-
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
10 changed files
with
295 additions
and
15 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
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,4 @@ | ||
# Puppet Server Provisioner | ||
|
||
Articles about using the `puppet_server` provisioner where code must work with a Puppet Server. | ||
|
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,65 @@ | ||
# Hello Web Project | ||
|
||
## Instructions | ||
|
||
1. Setup `bash setup.sh` | ||
2. Launch Guests | ||
```bash | ||
vagrant up --no-provision | ||
``` | ||
3. Install Server | ||
```bash | ||
vagrant provision puppetserver01 --provision-with "bootstrap" | ||
vagrant ssh puppetserver01 \ | ||
--command "sudo /opt/puppetlabs/bin/puppetserver ca list --all" | ||
``` | ||
4. Install Agents | ||
```bash | ||
for NODE in node0{1..2}; do | ||
vagrant provision $NODE --provision-with "bootstrap" | ||
done | ||
``` | ||
5. Issue Certificate Requests | ||
```bash | ||
for NODE in node0{1..2}; do | ||
printf "\n$NODE: Testing connection (expect failure)\n" | ||
vagrant ssh $NODE --command 'sudo /opt/puppetlabs/bin/puppet agent --test' | ||
done | ||
``` | ||
6. Verify | ||
```bash | ||
vagrant ssh puppetserver01 --command "sudo /opt/puppetlabs/bin/puppetserver ca list" | ||
``` | ||
7. Sign Certificates | ||
```bash | ||
for NODE in node0{1..2}.local; do | ||
printf "\nSigning $NODE\n" | ||
vagrant ssh puppetserver01 --command \ | ||
"sudo /opt/puppetlabs/bin/puppetserver ca sign --certname $NODE" | ||
done | ||
``` | ||
8. Verify | ||
```bash | ||
vagrant ssh puppetserver01 --command "sudo /opt/puppetlabs/bin/puppetserver ca list --all" | ||
``` | ||
9. Test Connectivity | ||
```bash | ||
for NODE in node0{1..2}; do | ||
printf "\n$NODE: Testing connection (expect success)\n" | ||
vagrant ssh $NODE --command 'sudo /opt/puppetlabs/bin/puppet agent --test' | ||
done | ||
``` | ||
10. Provision | ||
```bash | ||
for NODE in node0{1..2}; do vagrant provision $NODE; done | ||
``` | ||
11. Test Results | ||
```bash | ||
for NODE in node0{1..2}; do | ||
vagrant ssh $NODE --command "curl --include localhost" | ||
done | ||
``` | ||
12. Cleanup | ||
```bash | ||
vagrant destroy --force | ||
``` |
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,35 @@ | ||
Vagrant.configure("2") do |config| | ||
config.vm.provision "bootstrap", before: :all, | ||
type: "shell", path: "./bootstrap.sh" | ||
|
||
# Puppet Master node | ||
config.vm.define "puppetserver01" do |puppetserver| | ||
puppetserver.vm.box = "generic/ubuntu2204" | ||
puppetserver.vm.hostname = "puppetserver01.local" | ||
puppetserver.vm.network "private_network", ip: "192.168.50.4" | ||
puppetserver.vm.synced_folder "site", | ||
"/etc/puppetlabs/code/environments/production" | ||
end | ||
|
||
# Node 1 | ||
config.vm.define "node01" do |node01| | ||
node01.vm.box = "generic/ubuntu2204" | ||
node01.vm.hostname = "node01.local" | ||
node01.vm.network "private_network", ip: "192.168.50.5" | ||
node01.vm.provision "puppet_server" do |puppet| | ||
puppet.puppet_server = "puppetserver01.local" | ||
puppet.options = "--verbose --debug" | ||
end | ||
end | ||
|
||
# Node 2 | ||
config.vm.define "node02" do |node02| | ||
node02.vm.box = "generic/ubuntu2204" | ||
node02.vm.hostname = "node02.local" | ||
node02.vm.network "private_network", ip: "192.168.50.6" | ||
node02.vm.provision "puppet_server" do |puppet| | ||
puppet.puppet_server = "puppetserver01.local" | ||
puppet.options = "--verbose --debug" | ||
end | ||
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,89 @@ | ||
#!/usr/bin/env bash | ||
|
||
# global variables | ||
PUPPET_FQDN="puppetserver01.local" | ||
HOSTNAME_FQDN="$(hostname -f)" | ||
HOSTS_ENTRIES="192.168.50.4 puppetserver01.local puppetserver01 | ||
192.168.50.5 node01.local node01 | ||
192.168.50.6 node02.local node02" | ||
|
||
# main | ||
main() { | ||
if [[ "$HOSTNAME_FQDN" == "$PUPPET_FQDN" ]]; then | ||
setup_hosts_file | ||
if ! systemctl status puppetserver > /dev/null; then | ||
install_puppet_server | ||
configure_puppet_server "$PUPPET_FQDN" | ||
sudo systemctl start puppetserver | ||
systemctl status puppetserver && sudo systemctl enable puppetserver | ||
else | ||
echo "Puppet Server is already installed! skipping" | ||
fi | ||
else | ||
setup_hosts_file | ||
if ! command -v puppet > /dev/null; then | ||
install_puppet_agent | ||
configure_puppet_agent "$PUPPET_FQDN" "$HOSTNAME_FQDN" | ||
else | ||
echo "The Puppet Agent is already installed! skipping" | ||
fi | ||
fi | ||
} | ||
|
||
# setup /etc/hosts file | ||
setup_hosts_file() { | ||
if [[ "$HOSTNAME_FQDN" == "$PUPPET_FQDN" ]]; then | ||
grep -q 'puppet$' /etc/hosts \ | ||
|| sudo sed -i '/127\.0\.0\.1 localhost/s/$/ puppet/' /etc/hosts | ||
fi | ||
|
||
while read -r ENTRY; do | ||
grep -q ${ENTRY##* } /etc/hosts || \ | ||
sudo sh -c "echo '$ENTRY' >> /etc/hosts" | ||
done <<< "$HOSTS_ENTRIES" | ||
} | ||
|
||
# add remote registry for puppet packages | ||
add_puppet_registry() { | ||
wget https://apt.puppetlabs.com/puppet8-release-$(lsb_release -cs).deb | ||
sudo dpkg -i puppet8-release-$(lsb_release -cs).deb | ||
} | ||
|
||
# install puppet agent | ||
install_puppet_agent() { | ||
add_puppet_registry | ||
sudo apt-get -qq update | ||
sudo apt-get install -y puppet-agent | ||
} | ||
|
||
# install puppet server | ||
install_puppet_server() { | ||
add_puppet_registry | ||
sudo apt-get -qq update | ||
sudo apt-get install -y puppetserver | ||
} | ||
|
||
# configure puppet server | ||
configure_puppet_server() { | ||
# add entries if they do not yet exist | ||
grep -q "dns_alt_names" /etc/puppetlabs/puppet/puppet.conf \ | ||
|| sudo sh -c \ | ||
"echo 'dns_alt_names = $1,${1%%.*},puppet' >> /etc/puppetlabs/puppet/puppet.conf" | ||
grep -q "certname" /etc/puppetlabs/puppet/puppet.conf \ | ||
|| sudo sh -c "echo 'certname = $1' >> /etc/puppetlabs/puppet/puppet.conf" | ||
|
||
# set default memory for test vm guest | ||
sudo sed -i \ | ||
's/JAVA_ARGS="-Xms2g -Xmx2g/JAVA_ARGS="-Xms512m -Xmx512m/' \ | ||
/etc/default/puppetserver | ||
} | ||
|
||
# configure puppet agent | ||
configure_puppet_agent() { | ||
sudo bash -c "cat << EOF > /etc/puppetlabs/puppet/puppet.conf | ||
server = $1 | ||
certname = $2 | ||
EOF" | ||
} | ||
|
||
main |
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,16 @@ | ||
#!/usr/bin/env bash | ||
|
||
PROJ_HOME=~/vagrant-puppetserver | ||
|
||
# craete directory structure | ||
mkdir -p \ | ||
$PROJ_HOME/site/{data,manifests,modules/hello_web/{files,manifests}} | ||
|
||
cd $PROJ_HOME | ||
|
||
# create files | ||
touch \ | ||
Vagrantfile \ | ||
bootstrap.sh \ | ||
site/manifests/site.pp \ | ||
site/modules/hello_web/{manifests/init.pp,files/index.html,metadata.json} |
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,7 @@ | ||
node "node01.local" { | ||
class { 'hello_web': } | ||
} | ||
|
||
node "node02.local" { | ||
class { 'hello_web': } | ||
} |
5 changes: 5 additions & 0 deletions
5
vagrant/puppet_server/hello_web_proj/site/modules/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> |
19 changes: 19 additions & 0 deletions
19
vagrant/puppet_server/hello_web_proj/site/modules/hello_web/manifests/init.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,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", | ||
} | ||
} |
21 changes: 21 additions & 0 deletions
21
vagrant/puppet_server/hello_web_proj/site/modules/hello_web/metadata.json
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,21 @@ | ||
{ | ||
"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": "Ubuntu", | ||
"operatingsystemrelease": ["22.04"] | ||
} | ||
], | ||
"requirements": [ | ||
{ | ||
"name": "puppet", | ||
"version_requirement": ">= 7.24 < 9.0.0" | ||
} | ||
] | ||
} |