Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
update-puppet-modules.pl
#!/usr/bin/perl -w
use Switch;
# check we are root first
if ( $< != 0 ) {
print "This script must be run as root\n";
exit (0);
}
# Grab list of installed modules
my @return = `puppet module list --modulepath=/etc/puppet/modules | grep ─`;
# Loop through return data, split it and stuff all the module names into @modules
my @modules;
foreach (@return) {
my @temp = split(/ /, $_);
push (@modules, $temp[1]);
}
# Loop through list of modules and see if they are the latest
foreach $module (@modules) {
my $status = `puppet module upgrade $module --ignore-changes 2>&1`;
switch ($status) {
# Suppress output for modules that weren't upgraded
case /The installed version is already the latest version/ {
print "$module is already the latest version\n";
} case /The installed version is already the best fit for the current dependencies/ {
print "$module is already the best fit\n";
} else {
print $status;
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment