Skip to content

Commit

Permalink
Load puppet versions from shared file
Browse files Browse the repository at this point in the history
This will allow scripts for different operating systems to be separated and still use the same versions

This also helps keep track of what facter versions are being used with each version of Puppet Agent.

Tested on RHEL 9, Fedora 38, Ubuntu 20.04, Windows 10, Windows Server 2019

Inspired by voxpupuli#330
  • Loading branch information
root committed May 15, 2024
1 parent 9ba6d88 commit efa22ec
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 2 deletions.
12 changes: 11 additions & 1 deletion facts/get_facts.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,17 @@

export PATH=/opt/puppetlabs/bin:$PATH

puppetAgentVersionList='/vagrant/versions.txt'
if test ! -f $puppetAgentVersionList; then
echo 'Missing version list' >&2
exit 1
fi
puppet8_agent_versions=$(grep --only-matching --perl-regexp '^\d+\.\d+\.\d+' $puppetAgentVersionList)
if test -z "$puppet8_agent_versions"; then
echo 'Version list is empty' >&2
exit 1
fi

apt_install() {
DEBIAN_FRONTEND=noninteractive \
apt-get --option Dpkg::Options::="--force-confdef" \
Expand Down Expand Up @@ -42,7 +53,6 @@ elif test -f '/etc/os-release' && grep -q 'Amazon' '/etc/os-release'; then
else
osfamily=$(uname)
fi
puppet8_agent_versions='8.0.0 8.1.0 8.2.0 8.3.1 8.4.0 8.5.0 8.5.1 8.6.0'
case "${osfamily}" in
'RedHat')
. /etc/os-release
Expand Down
16 changes: 16 additions & 0 deletions facts/versions.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
# This is a list of all Puppet Agent versions to use to collect facts
# Each line can have a single string which is a version number or can be a comment
# Version information from Facter release notes: https://www.puppet.com/docs/puppet/8/release_notes_facter.htm
# FacterDB only cares about the x.y, and drops .z - Please keep versions in order by Facter version

# Facter 4.7.0 - Released April 2024 and shipped with Puppet 8.6.0.
8.6.0

# Facter 4.6.1 - Released March 2024 and shipped with Puppet 8.5.1.
8.5.1

# Facter 4.5.2 - Released January 2023 and shipped with Puppet 8.4.0.
8.4.0

# Facter 4.4.2 - Released August 2023 and shipped with Puppet 8.2.0.
8.2.0
15 changes: 14 additions & 1 deletion facts/windows_get_facts.ps1
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
param(
[array]$puppetAgentVersions = ('7.24.0','8.0.0','8.5.1','8.6.0'),
[string]$puppetAgentVersionList = 'X:\versions.txt',
[string]$baseUrl = 'https://downloads.puppetlabs.com/windows/puppet{0}/puppet-agent-{1}-{2}.msi',
[string]$fqdn = 'foo.example.com'
)
Expand All @@ -25,6 +25,18 @@ net use X: \\VBOXSVR\vagrant
$VagrantDataPath = 'X:\'
$WorkingDirectory = 'C:\vagrant_working_directory\'

# Check if version list is available and load it
if (!(Test-Path $puppetAgentVersionList)) {
Write-Host -ForegroundColor Red "Can't find Puppet Agent Version list."
Exit 1
}

$puppetAgentVersions = Select-String -Path $puppetAgentVersionList '^\d+\.\d+\.\d+' -AllMatches | Foreach-Object {$_.Line}
if ($puppetAgentVersions.Count -eq 0) {
Write-Host -ForegroundColor Red "Puppet Agent version list seems to be empty."
Exit 1
}

# Make sure we have enough privs to install the things.
$currentPrincipal = New-Object Security.Principal.WindowsPrincipal([Security.Principal.WindowsIdentity]::GetCurrent())
if (! ($currentPrincipal.IsInRole([Security.Principal.WindowsBuiltInRole]::Administrator))) {
Expand All @@ -40,6 +52,7 @@ if (!(Test-Path $WorkingDirectory)) {

# Install each puppet version & collect facts.
foreach ($pupAgentVer in $puppetAgentVersions) {
write-Host "Generating facts with `'$pupAgentVer`'"

$agentUrl = $baseUrl -f $pupAgentVer[0], $pupAgentVer, "x64"
$agentName = "puppet-agent-{1}-{2}.msi" -f $pupAgentVer[0], $pupAgentVer, "x64"
Expand Down

0 comments on commit efa22ec

Please sign in to comment.