Skip to content

Instantly share code, notes, and snippets.

@djjudas21
Created January 6, 2015 09:34
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save djjudas21/933d90d3a1c267a6e884 to your computer and use it in GitHub Desktop.
Save djjudas21/933d90d3a1c267a6e884 to your computer and use it in GitHub Desktop.
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