Created
January 6, 2015 09:34
-
-
Save djjudas21/933d90d3a1c267a6e884 to your computer and use it in GitHub Desktop.
update-puppet-modules.pl
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
#!/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