· 9 years ago · Nov 23, 2016, 06:12 PM
1{
2 "variables": {
3 "aws_access_key": "", // This helps me connect to AWS
4 "aws_secret_key": ""
5 },
6 "builders": [{
7 "type": "amazon-ebs",
8 "access_key": "{{user `aws_access_key`}}",
9 "secret_key": "{{user `aws_secret_key`}}",
10 "region": "us-east-1",
11 "source_ami": "SECRET_MASK",
12 "instance_type": "t2.micro",
13 "ssh_username": "root",
14 "ami_name": "vimn_drupal_base_{{timestamp}}",
15 "vpc_id": "SECRET_MASK",
16 "subnet_id": "SECRET_MASK"
17 }],
18 "provisioners": [{
19 "type": "shell",
20 "inline": ["sleep 10"] // At first you want the shell to sleep for sometime, so that SSH is available
21 }, {
22 "type": "shell",
23 "inline": [
24 "yum install -y epel-release", // I needed this to be able to install extra yum packages
25 "yum install -y ansible" // You need to install ansible on your AWS box. Because ansible playbook would run locally
26 ]
27 }, {
28 "type": "ansible-local",
29 "playbook_file": "../ansible/single_vbox_drupal/packer-ec2-ami.yml", // This runs your plays / roles locally
30 "role_paths": [ // This copies the roles to newly created AWS ec2
31 "../ansible/single_vbox_drupal/roles/common",
32 "../ansible/single_vbox_drupal/roles/apache",
33 "../ansible/single_vbox_drupal/roles/drush",
34 "../ansible/single_vbox_drupal/roles/mysql",
35 "../ansible/single_vbox_drupal/roles/php",
36 "../ansible/single_vbox_drupal/roles/site"
37 ],
38 "group_vars": "../ansible/single_vbox_drupal/group_vars/all", // useful to tell ansible, not must
39 "playbook_dir": "../ansible/single_vbox_drupal" // useful to tell ansible, not must
40 }, {
41 "type": "shell",
42 "inline": [
43 "rm -rf /root/.ssh/authorized_keys" // I need this so that the new AMI would work with the KEY I create in my AWS account. This is because of a CentOS bug.
44 ]
45
46 }]
47}