Skip to content

Instantly share code, notes, and snippets.

@joeypiccola
Last active September 4, 2018 16:53
Show Gist options
  • Save joeypiccola/6b2eda5adaecc2b8209f371d0839adbd to your computer and use it in GitHub Desktop.
Save joeypiccola/6b2eda5adaecc2b8209f371d0839adbd to your computer and use it in GitHub Desktop.
# node & agent data
$master = 'puppet'
$role = 'base'
$environment = 'production'
# facts data
$teams = 'isg,sdm' # comma seperated list
$project = ''
$datacenter = 'denver' # maybe you need this maybe you don't
$application = ''
$application_environment = ''
# fix team data
$teamsfix = @()
if ($teams -ne '') {
$teams -split ',' | %{$_ -replace '\s',''} | ?{$_ -ne ''} | %{$teamsfix += $_}
} else {
$teamsfix = @()
}
# build puppet data object
$puppet_cfg = [PSCustomObject]@{
role = $role
environment = $environment
facts = [PSCustomObject]@{
teams = $teamsfix
project = if ($project) {$project} else {Write-Output ''}
datacenter = $datacenter
application = if ($application) {$application} else {Write-Output ''}
application_environment = if ($application_environment) {$application_environment} else {Write-Output ''}
}
}
# define config and setup json
$puppet_cfg_json = $puppet_cfg | ConvertTo-Json
New-Item -Path 'C:\deploy\' -ItemType Directory -Force
Add-Content -Path 'C:\deploy\puppet_cfg.json' -Value $puppet_cfg_json -Force
$puppet_fact_json = $puppet_cfg.facts | ConvertTo-Json
New-Item -Path 'C:\ProgramData\PuppetLabs\facter\facts.d\' -ItemType Directory -Force
$factPath = 'C:\ProgramData\PuppetLabs\facter\facts.d\piccola.json'
# force UTF8 with no BOM to make facter happy (Out-File -Encoding UTF8 does not work, Add-Content does not work, >> does not work)
$Utf8NoBomEncoding = New-Object System.Text.UTF8Encoding $False
[System.IO.File]::WriteAllLines($factPath, $puppet_fact_json, $Utf8NoBomEncoding)
# initiate install
[Net.ServicePointManager]::ServerCertificateValidationCallback = {$true}; $webClient = New-Object System.Net.WebClient; $webClient.DownloadFile("https://$master`:8140/packages/current/install.ps1", 'install.ps1'); .\install.ps1 extension_requests:pp_role=$role agent:environment=$environment
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment