Created
February 22, 2016 20:04
-
-
Save swade1987/584932c675edc10a40da to your computer and use it in GitHub Desktop.
packer windows ami
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
"variables": { | |
"aws_access_key": "{{env `AWS_ACCESS_KEY`}}", | |
"aws_secret_key": "{{env `AWS_SECRET_KEY`}}", | |
"atlas_username": "", | |
"atlas_token": "", | |
"name": "aws-windows-base", | |
"region": "us-west-2", | |
"vpc_id": "vpc-6aa9440e", | |
"subnet_id": "subnet-3c042265", | |
"source_ami": "ami-b74aaed7", | |
"instance_type": "t2.micro", | |
"winrm_username": "steven", | |
"winrm_password": "St3v3nw4d3!", | |
"user_data_file": "packer/scripts/windows/config/ec2_user_data.conf", | |
"scripts_dir": "packer/scripts/windows" | |
}, | |
"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_port": 5985, | |
"winrm_timeout": "20m", | |
"ssh_private_ip": "false", | |
"user_data_file": "{{user `user_data_file`}}", | |
"ami_name": "{{user `name`}} {{timestamp}}", | |
"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_chef.ps1" | |
] | |
}, | |
{ | |
"type": "chef-solo", | |
"skip_install": true, | |
"cookbook_paths": ["cookbooks"], | |
"run_list": ["core::default"] | |
}, | |
{ | |
"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'}}\"" | |
} | |
], | |
"post-processors": [ | |
{ | |
"type": "atlas", | |
"token": "{{user `atlas_token`}}", | |
"artifact": "{{user `atlas_username`}}/{{user `name`}}", | |
"artifact_type": "amazon.ami", | |
"metadata": { | |
"version": "0.0.1", | |
"created_at": "{{timestamp}}" | |
} | |
} | |
] | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment