Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
packer file
{
"variables": {
"aws_access_key": "{{env `AWS_ACCESS_KEY`}}",
"aws_secret_key": "{{env `AWS_SECRET_KEY`}}",
"atlas_username": "{{env `ATLAS_USERNAME`}}",
"atlas_token": "AGatG6zR7NjPRg.atlasv1.JrueNghrDyMItxjyzeotL87l26ymHb9MLzTlkyaf5joZH5cMg0kpViaR3qCr9iDOE9Y",
"name": "aws-windows-base",
"region": "us-west-2",
"vpc_id": "",
"subnet_id": "",
"source_ami": "ami-b74aaed7",
"instance_type": "t2.micro",
"winrm_username": "Administrator",
"winrm_password": "Password1",
"user_data_file": "packer/scripts/windows/config/ec2_user_data.conf",
"scripts_dir": "packer/scripts/windows",
"cookbooks_dir": "cookbooks"
},
"push": {
"name": "{{user `atlas_username`}}/{{user `name`}}",
"base_dir": "../../../.",
"include": [
"{{user `user_data_file`}}",
"{{user `scripts_dir`}}/*"
],
"vcs": false
},
"builders": [
{
"type": "amazon-ebs",
"access_key": "{{user `aws_access_key`}}",
"secret_key": "{{user `aws_secret_key`}}",
"region": "{{user `region`}}",
"vpc_id": "{{user `vpc_id`}}",
"subnet_id": "{{user `subnet_id`}}",
"source_ami": "{{user `source_ami`}}",
"instance_type": "{{user `instance_type`}}",
"communicator": "winrm",
"winrm_username": "{{user `winrm_username`}}",
"winrm_password": "{{user `winrm_password`}}",
"winrm_timeout": "60m",
"user_data_file": "{{user `user_data_file`}}",
"ami_name": "{{user `name`}}",
"ami_description": "{{user `name`}} AMI",
"run_tags": { "ami-create": "{{user `name`}}" },
"tags": { "ami": "{{user `name`}}" },
"associate_public_ip_address": true
}
],
"provisioners": [
{
"type": "powershell",
"scripts": [
"{{user `scripts_dir`}}/install_windows_updates.ps1"
]
},
{
"type": "windows-restart",
"restart_command": "powershell \"& {(Get-WmiObject win32_operatingsystem).LastBootUpTime > C:\\ProgramData\\lastboot.txt; Restart-Computer -force}\"",
"restart_check_command": "powershell -command \"& {if ((get-content C:\\ProgramData\\lastboot.txt) -eq (Get-WmiObject win32_operatingsystem).LastBootUpTime) {Write-Output 'Waiting for restart'; start-sleep 600} else {Write-Output 'Restart complete'}}\""
},
{
"type": "powershell",
"scripts": [
"{{user `scripts_dir`}}/install_windows_updates.ps1"
]
},
{
"type": "windows-restart",
"restart_command": "powershell \"& {(Get-WmiObject win32_operatingsystem).LastBootUpTime > C:\\ProgramData\\lastboot.txt; Restart-Computer -force}\"",
"restart_check_command": "powershell -command \"& {if ((get-content C:\\ProgramData\\lastboot.txt) -eq (Get-WmiObject win32_operatingsystem).LastBootUpTime) {Write-Output 'Waiting for restart'; start-sleep 600} else {Write-Output 'Restart complete'}}\""
},
{
"type": "chef-solo",
"cookbook_paths": ["{{user `cookbooks_dir`}}"],
"run_list": ["core::default"]
}
],
"post-processors": [
{
"type": "atlas",
"token": "{{user `atlas_token`}}",
"artifact": "{{user `atlas_username`}}/{{user `name`}}",
"artifact_type": "amazon.ami",
"metadata": {
"created_at": "{{timestamp}}"
}
}
]
}
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.