Skip to content

Instantly share code, notes, and snippets.

@marcy-terui
Last active August 29, 2015 14:02
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save marcy-terui/98cfa0ed35a92eb6a980 to your computer and use it in GitHub Desktop.
Save marcy-terui/98cfa0ed35a92eb6a980 to your computer and use it in GitHub Desktop.
$AWSAccessKey = "YOUR_ACCESS_KEY"
$AWSSecretKey = "YOUR_SECRET_KEY"
$Region = "ap-northeast-1"
$ProfileName = "YOUR_PROFILE_NAME"
$BucketName = "YOUR_BUCKET_NAME"
$BucketKey = "YOUR_OBJECT_KEY"
$LocalPath = "C:\\chef\\validation.pem"
$ChefServerUrl = "YOUR_SERVER_URL"
$Environment = "YOUR_ENVIRONMENT"
$SpanMinutes = 5
$DurationDays = 8192
Set-ExecutionPolicy "RemoteSigned" -Force
(new-object System.Net.WebClient).DownloadFile("http://sdk-for-net.amazonwebservices.com/latest/AWSToolsAndSDKForNet.msi", "C:\\Users\\Administrator\\awstools.msi") | Out-Null
msiexec /i "C:\\Users\\Administrator\\awstools.msi" /l*v "C:\\Users\\Administrator\\aws_tools_install.log" /qn | Out-Null
(new-object System.Net.WebClient).DownloadFile("https://opscode-omnibus-packages.s3.amazonaws.com/windows/2008r2/x86_64/chef-windows-11.12.8-2.windows.msi", "C:\\Users\\Administrator\\chef.msi") | Out-Null
msiexec /i "C:\\Users\\Administrator\\chef.msi" /l*v "C:\\Users\\Administrator\\chef_install.log" /qn | Out-Null
import-module "C:\Program Files (x86)\AWS Tools\PowerShell\AWSPowerShell\AWSPowerShell.psd1"
Set-AWSCredentials -AccessKey $AWSAccessKey -SecretKey $AWSSecretKey -StoreAs $ProfileName
Initialize-AWSDefaults -ProfileName $ProfileName -Region $Region
Read-S3Object -BucketName $BucketName -Key $BucketKey -File C:\chef\validation.pem
$env:Path = $env:Path + ";C:\opscode\chef\bin"
$hostname = $Env:COMPUTERNAME
$clientfile = @"
log_level :info
log_location STDOUT
node_name "${hostname}"
chef_server_url '${ChefServerUrl}'
validation_client_name 'chef-validator'
environment '${Environment}'
"@
[System.IO.File]::WriteAllLines("C:\chef\client.rb", $clientfile)
$trigger = New-JobTrigger -Once -RepetitionInterval (New-TimeSpan -Minutes $SpanMinutes) -RepetitionDuration (New-TimeSpan -Days $DurationDays) -At (Get-Date)
Register-ScheduledJob -Name "ChefClient" -ScriptBlock { C:\opscode\chef\bin\chef-client.bat } -Trigger $trigger -RunNow
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment