My best practice of project structure to provison AWS EC2 AMI with Packer.
This repository requires following runtime environment and modules.
- Mac OSX
- Python (3.6.1 or more)
- Packer (1.1.3 or more)
- Ansible (2.3.1.0 or more)
- Ruby (2.4 or more)
- AWS CLI (1.14.30 or more)
- Virtualbox (5.2.12 or more)
- Vagrant (2.1.1 or more)
- Install ansible
pip install -r requirements.txt -c constraints.txt
- Boot vargrant instance, initialize and take vagrant snapshot for rollback.
make init-vagrant
- Provison to vagrant instance with null provisioner, and rollback to initial instance state.
ROLE
: role name linked ansible-playbook file.
make test-local ROLE=hoge
- Edit your aws credential information on
~/.aws/credentials
.
[your-profile]
aws_access_key_id = [your access_key_id]
aws_secret_access_key = [your_secret_access_key]
region = [your region]
- Edit
packer/env-aws-variables.json
that includes packer setting for AWS provisioning.
{
"aws_region": "your-region",
"aws_vpc_id": "vpc-xxxxxxxxxxxxxx",
"aws_subnet_id": "subnet-xxxxxxxxxxx",
"ssh_user": "centos",
"use_profile": "your-profile",
"aws_instance_role": "your-packer-role",
"aws_keypair_name": "your-keypair-name"
}
- Provision AWS instacne
make create-ami ROLE=hoge AWS_KEY_FILE=${absolute path to aws key file for ssh to instance}