Skip to content

Instantly share code, notes, and snippets.

@vniklas
Created December 8, 2016 13:48
Show Gist options
  • Select an option

  • Save vniklas/aa509db8797d5e94f49470f1945501e4 to your computer and use it in GitHub Desktop.

Select an option

Save vniklas/aa509db8797d5e94f49470f1945501e4 to your computer and use it in GitHub Desktop.
# upgrading puppet with choco
#
# Niklas Akerlund
# Get version of puppet agent
$puppetversion = & puppet agent --version
# Get the latest run of puppet
$lastrun = Get-WinEvent -ProviderName Puppet -MaxEvents 35 | where {$_.Message -like "*Finished*" -or $_.Message -like "Applied*"} | sort TimeCreated -Descending | select -First 1 | select -ExpandProperty TimeCreated
$datenow = Get-Date
# Check version and if old version update
if ($puppetversion -lt "4.8.1" -and $lastrun){
# Only update if there is no puppet apply running
if ($datenow -ge $lastrun.AddMinutes(5) -and $datenow -le $lastrun.AddMinutes(25) -and !(get-process ruby -ErrorAction SilentlyContinue)){
# update Puppet client to great success version
choco upgrade puppet-agent --y
Write-output "fixitrix update "
}else{
Write-Output "To close to apply will try again"
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment