Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add Vagrant setup for testing and development #519

Merged
merged 3 commits into from
Feb 14, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .dockerignore
Original file line number Diff line number Diff line change
Expand Up @@ -9,3 +9,4 @@ docker-compose.yml
Gemfile.lock
screenshots/
vendor/bundle
vagrant
77 changes: 77 additions & 0 deletions vagrant/Vagrantfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
# frozen_string_literal: true

require 'yaml'
require 'ipaddr'
# Required Vagrant plugins
plugins = [
'hostmanager',
'vbguest',
'disksize',
]
# Nodes configuration is defined in config.yaml
config_file = File.join(__dir__, 'config.yaml')
# mount path for repo on VMs
code_dir = '/vagrant_foreman'
# Initial vms hash
vms = {}

# Sanity checks
unless File.exist?(config_file)
puts 'File config.yaml not found. Must be in same dir of Vagrantfile'
abort
end
plugins.each do |plugin|
unless Vagrant.has_plugin?("vagrant-#{plugin}")
puts "ERROR! Wir benoetigen das plugin vagrant-#{plugin}: vagrant plugin install vagrant-#{plugin}"
abort
end
end

# read config
config = YAML.load_file config_file

# parse config, merge defaults, add required data
config['nodes'].each do |node, conf|
vms[node] = {}
vms[node] = config['default'].merge conf
vms[node]['fqdn'] = format('%<role>s.%<domain>s', role: node, domain: vms[node]['domain'])
vms[node]['aliases'] = [
format('%<role>s.%<domain>s %<role>s', role: node, domain: vms[node]['domain'])
]
end

# Vagrant configuration
Vagrant.configure('2') do |config|
# defaults for all vms
config.hostmanager.enabled = true
config.hostmanager.manage_host = true
config.hostmanager.ignore_private_ip = false
config.hostmanager.include_offline = true
config.vm.synced_folder '../', code_dir, mount_options: ['ro']

# See https://github.com/mitchellh/vagrant/issues/1673
config.ssh.shell = "bash -c 'BASH_ENV=/etc/profile exec bash'"

# config per vm
vms.each do |node, settings|
config.vm.define settings['fqdn'] do |setting|
setting.vm.box = settings['box']
setting.vm.box_url = settings['box_url'] unless settings['box_url'].nil?
setting.vm.hostname = settings['fqdn']
setting.vm.network :private_network, ip: settings['ip']
setting.vbguest.auto_update = false
setting.vm.provision 'shell', path: './sethostname.sh', args: settings['fqdn'].to_s
setting.hostmanager.aliases = settings['aliases']
# bootstrap foreman server
if node == 'puppet'
setting.disksize.size = '100GB'
setting.vm.provision 'shell', path: settings['script'].to_s
end
setting.vm.provider 'virtualbox' do |v|
v.customize ['modifyvm', :id, '--name', settings['fqdn']]
v.customize ['modifyvm', :id, '--cpus', settings['cpu'].to_s]
v.customize ['modifyvm', :id, '--memory', settings['memory'].to_s]
end
end
end
end
66 changes: 66 additions & 0 deletions vagrant/centos_script.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
#!/bin/bash

echo "DNF: Clean metadata"
sudo dnf clean all

echo "Installing Repo Packages"
echo "foreman"
sudo dnf -y localinstall https://yum.theforeman.org/releases/3.13/el9/x86_64/foreman-release.rpm
echo "Puppet 7"
sudo dnf -y localinstall https://yum.puppet.com/puppet8-release-el-9.noarch.rpm

echo "DNF update"
sudo dnf -y update

echo "installing some tools: tree vim net-tools"
sudo dnf -y install tree vim net-tools

echo "Katello installation part"
sudo dnf -y install foreman-installer

echo "Fix /etc/hosts"
sudo sed -i -e "/127.0.1.1 p/d" /etc/hosts

echo "Foreman Installation"
sudo foreman-installer \
--scenario foreman \
--enable-foreman-plugin-remote-execution \
--enable-foreman-proxy-plugin-remote-execution-script \
--enable-foreman-cli-remote-execution \
--enable-foreman-cli-tasks \
--enable-foreman-plugin-tasks \
--enable-foreman-plugin-puppetdb \
--foreman-initial-admin-password='betadots_foreman_2024'

echo "Installing puppet modules"
sudo /opt/puppetlabs/puppet/bin/puppet module install puppetlabs-puppetdb
sudo /opt/puppetlabs/puppet/bin/puppet module install puppet-hdm --ignore-dependencies
sudo /opt/puppetlabs/puppet/bin/puppet module install puppetlabs-docker --ignore-dependencies
sudo /opt/puppetlabs/puppet/bin/puppet module install ipcrm-echo --ignore-dependencies

echo "Preparing Puppet Environment"
sudo mkdir -p /etc/puppetlabs/code/environments/production/data/nodes
sudo mkdir -p /etc/puppetlabs/code/environments/production/manifests
sudo cp /vagrant/hdm/site.pp /etc/puppetlabs/code/environments/production/manifests/site.pp
sudo cp /vagrant/hdm/centos_data.yaml /etc/puppetlabs/code/environments/production/data/nodes/puppet.workshop.betadots.training.yaml
sudo cp /vagrant/hdm/common_data.yaml /etc/puppetlabs/code/environments/production/data/common.yaml

echo "Running Puppet"
sudo /opt/puppetlabs/puppet/bin/puppet agent -t
sudo puppet config set --section main reports foreman,puppetdb
sudo systemctl restart puppetserver

echo "Installing Foreman HDM"
sudo foreman-installer --enable-foreman-plugin-hdm --enable-foreman-proxy-plugin-hdm --foreman-proxy-plugin-hdm-hdm-url http://puppet.workshop.betadots.training:3000

echo "Uploading facts to PuppetDB"
sudo /opt/puppetlabs/bin/puppet agent -t

echo "Jetzt einloggen, root user werden"
echo "vagrant ssh puppet.betadots.training"
echo "sudo -i"
echo "### HDM:"
echo "Im Browser: https://puppet.betadots.training"
echo "Login: admin, Passwort: betadots_foreman_2024"
echo " -> Infrastructure -> Smart Proxies -> Refresh"
echo " -> Hosts -> All Hosts -> puppet.betadots.training -> Edit -> HDM Smart Proxy hinzufügen."
24 changes: 24 additions & 0 deletions vagrant/config.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
---
# Default settings for all vms (they can be overridden on each node)
default:
memory: 1612 # MB or RAM to assign - CentOS Installer needs at leas 1512 MB
# box_url: 'http://cloud.centos.org/centos/8/x86_64/images/CentOS-8-Vagrant-8.4.2105-20210603.0.x86_64.vagrant-virtualbox.box'
box: boxomatic/centos-stream-9 # Box used for the VM
# box: debian/bookworm64 # Box used for the VM
cpu: 1 # Number of vCPU to assign to the VM
domain: workshop.betadots.training # Name of DNS domain for the created machines
script: './centos_script.sh'
# script: './debian_script.sh'

# List of nodes shown in vagrant status
nodes:
puppet:
memory: 8192
cpu: 4
ip: 10.100.10.101
# apache:
# ip: 10.100.10.103
# proxmox:
# ip: 10.100.10.110
# cpu: 4
# memory: 8192
12 changes: 12 additions & 0 deletions vagrant/hdm/centos_data.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
---
classes:
'90_hdm_class': 'hdm'
'91_puppetdb_class': 'puppetdb'
'92_puppetdb_master_class': 'puppetdb::master::config'

hdm::version: 'v3.1.0'
hdm::disable_authentication: true
postgresql::globals::manage_dnf_module: false
puppetdb::manage_firewall: false
puppetdb::postgres_version: '13'
puppetdb::manage_package_repo: false
10 changes: 10 additions & 0 deletions vagrant/hdm/common_data.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
---
lookup_options:
classes:
merge: 'deep'

classes: {}

profile::base::additional_packages:
- 'htop'

15 changes: 15 additions & 0 deletions vagrant/hdm/site.pp
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
File {
backup => false,
}
$classes_hash = lookup('classes', { 'value_type' => Hash, 'default_value' => {} })
$classes_hash.keys.sort.each |$key| {
if $classes_hash[$key] != '' {
contain $classes_hash[$key]
} else {
echo { $key:
message => "Class for ${key} on ${facts['networking']['fqdn']} is disabled",
withpath => false,
}
}
}
node default {}
4 changes: 4 additions & 0 deletions vagrant/sethostname.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
#!/bin/bash
hostn=$1
echo "### Setting hostname ${hostn}"
hostnamectl set-hostname --static $hostn
Loading