Last active
July 25, 2017 02:09
-
-
Save daniilyar/6478af7683d25e664f96 to your computer and use it in GitHub Desktop.
Packer config for provisioning AWS EBS AMIs
This file contains 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": { | |
"vault_pass": "{{ env `VAULT_PASS` }}", | |
"aws_access_key": "{{ env `AWS_ACCESS_KEY` }}", | |
"aws_secret_key": "{{ env `AWS_SECRET_KEY` }}", | |
"source_ami_id": "{{ env `SOURCE_AMI_ID` }}", | |
"playbook": "{{ env `PLAYBOOK` }}", | |
"ami_description": "{{ env `AMI_DESCRIPTION` }}", | |
"roles_path": "{{ env `ROLES_PATH` }}" | |
}, | |
"builders": [ | |
{ | |
"type": "amazon-ebs", | |
"region": "us-west-2", | |
"source_ami": "{{ user `source_ami_id` }}", | |
"instance_type": "t2.micro", | |
"ssh_username": "ubuntu", | |
"ami_name": "main_ubuntu_image_1", | |
"vpc_id": "vpc-XXXXXX", | |
"subnet_id": "subnet-YYYYYYYY", | |
"access_key": "{{ user `aws_access_key` }}", | |
"secret_key": "{{ user `aws_secret_key` }}", | |
"security_group_id": "sg-ZZZZZZZ", | |
"ami_description": "{{ user `ami_description` }}", | |
"tags": { | |
"OS": "Ubuntu", | |
"PLAYBOOK": "{{ user `playbook` }}", | |
"SOURCE_AMI_ID": "{{ user `source_ami_id` }}" | |
} | |
} | |
], | |
"provisioners": [ | |
{ "type": "shell", "inline": ["sudo apt-get update && sudo apt-get install python-setuptools python-dev build-essential -y && sudo easy_install pip && sudo pip install --upgrade ansible"] }, | |
{ "type": "file", "source": "{{ user `roles_path` }}", "destination": "/tmp/ansible" }, | |
{ "type": "shell", "inline": ["sudo mkdir -p /etc/ansible/roles && sudo mv /tmp/ansible/* /etc/ansible/roles"] }, | |
{ | |
"type": "ansible-local", | |
"playbook_file": "{{ user `playbook` }}", | |
"command": "echo '{{ user `vault_pass` }}' | ansible-playbook", | |
"extra_arguments": "--vault-password-file=/bin/cat" | |
}, | |
{ "type": "shell", "inline": [ "sudo rm -rf /etc/ansible/roles" ] }, | |
{ "type": "shell", "inline": [ "yes y | sudo pip uninstall ansible" ] } | |
] | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Packer config for provisioning AWS EBS AMIs. Features:
Example of how to launch this config from external shell script: