Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
######## Install Puppet ######
[Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12
Write-Output "Properties are as follows:"
Write-Output "------------------------------------"
Write-Output "Master: $(hostname)"
Write-Output "Environment: development"
Write-Output "Role: base"
Write-Output "Apptier: dev"
Write-Output "Provisioner: vra"
Write-Output "Datacenter: aws"
Write-Output "Image name: aon"
Write-Output "Department: asc"
Write-Output ""
Write-Output "Creating C:\Temp\Puppet:"
Write-Output "------------------------------------"
mkdir c:\temp\puppet
Write-Output ""
Write-Output "Downloading MSI to C:\Temp\Puppet:"
Write-Output "----------------------------------------------------"
#download the msi
[System.Net.ServicePointManager]::ServerCertificateValidationCallback = {$true} ;
$WebClient = New-Object System.Net.Webclient
$WebClient.DownloadFile("http://builds.delivery.puppetlabs.net/puppet-agent/a557133e0485297d08cfac7e31fd808b05ec38e2/artifacts/windows/puppet-agent-x64.msi", "c:\temp\puppet\puppet-agent-x64.msi")
Write-Output ""
Write-Output "Installing Puppet Agent"
Write-Output "--------------------------------"
#install the MSI package with the proper switches (no master)
start-process -filepath "msiexec.exe" -arg "/qn /norestart /l*v C:\windows\temp\puppetinstall.log /i c:\temp\puppet\puppet-agent-x64.msi PUPPET_AGENT_STARTUP_MODE=Manual" -Wait
write-output ""
Write-Output "Populating csr_attributes.yaml file:"
Write-Output "----------------------------------------------------"
$csr_attrib_file = "c:\programdata\puppetlabs\puppet\etc\csr_attributes.yaml"
Add-Content $csr_attrib_file "---"
Add-Content $csr_attrib_file "extension_requests:"
Add-Content $csr_attrib_file " pp_role: base"
Add-Content $csr_attrib_file " pp_environment: development"
Add-Content $csr_attrib_file " pp_apptier: dev"
Add-Content $csr_attrib_file " pp_provisioner: vra"
Add-Content $csr_attrib_file " pp_datacenter: aws"
Add-Content $csr_attrib_file " pp_image_name: aon"
Add-Content $csr_attrib_file " pp_department: asc"
Write-Output ""
Write-Output "Editing Puppet Agent Config:"
Write-Output "----------------------------------------"
start-process -filepath "C:\Program Files\Puppet Labs\Puppet\bin\puppet" -ArgumentList "config set server psconfeudsc.uamlrovyzzaevhmxceiugckycb.zx.internal.cloudapp.net --section main" -Wait
######## Puppet Run ########
[Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12
Write-Output "Running Puppet Agent"
Write-Output "-----------------------------"
start-process -filepath "C:\Program Files\Puppet Labs\Puppet\bin\puppet" -ArgumentList "config set server psconfeudsc.uamlrovyzzaevhmxceiugckycb.zx.internal.cloudapp.net --section main" -Wait
$numtries = 0
$success = 0
$stderr_log = "C:\temp\puppet_agent_stderr.txt"
$stdout_log = "C:\temp\puppet_agent_stdout.txt"
while ( $numtries -lt 5 -and $success -eq 0 ) {
$numtries++
Write-Output "***** Attempt $numtries *****"
$lock_exists = Test-Path "C:\Programdata\PuppetLabs\puppet\cache\state\agent_catalog_run.lock"
if ( $lock_exists ) {
Write-Output "***** Found Lock File, Waiting 1 Minute To Run *****"
Start-Sleep -s 60
}
# & "C:\Program Files\Puppet Labs\Puppet\bin\puppet" agent --test --detailed-exitcodes 2>$stderr_log
# $EC = $LASTEXITCODE
$puppet_run = start-process -filepath "C:\Program Files\Puppet Labs\Puppet\bin\puppet" -LoadUserProfile -argumentlist "agent --test --detailed-exitcodes" -Wait -PassThru -RedirectStandardError $stderr_log -RedirectStandardOutput $stdout_log
Get-Content $stdout_log
Get-Content $stderr_log
[String]$puppet_exit = $puppet_run.ExitCode
if ( $puppet_run.ExitCode -ne 0 ) {
Write-Output "***** Puppet Run Was Not Successful *****"
Write-Output "***** Exit Code was $puppet_exit *****"
} else {
Write-Output "***** Puppet Run Was Successful *****"
$success = 1
Write-Output "Setting Puppet Startup To Automatic and Starting Service"
Write-Output "--------------------------------------------------------------------------"
Set-Service puppet -StartupType Automatic
Start-Service puppet
}
}
if ( $success -eq 0 ) {
Write-Output "***** Puppet Run Failed After 5 Attempts *****"
exit 1
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.