This repository has been archived by the owner on Nov 26, 2019. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 9
/
packer-debian9-ec2ami.json
82 lines (80 loc) · 3.16 KB
/
packer-debian9-ec2ami.json
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
{
"variables": {
"ansible_roles_path": "./ansible/roles",
"aws_access_key_id": "{{env `AWS_ACCESS_KEY_ID`}}",
"aws_region": "{{env `AWS_REGION`}}",
"aws_secret_access_key": "{{env `AWS_SECRET_ACCESS_KEY`}}",
"aws_security_group_id": "{{env `AWS_SECURITY_GROUP_ID`}}",
"aws_subnet_id": "{{env `AWS_SUBNET_ID`}}",
"aws_vpc_id": "{{env `AWS_VPC_ID`}}",
"build_name": "packer-debian9-ec2ami",
"build_ref": "{{env `BUILD_REF`}}",
"build_id": "{{isotime \"20060102150405\"}}",
"source_ami": "{{env `SOURCE_AMI`}}",
"ami_regions": "{{env `AMI_REGIONS`}}"
},
"builders": [
{
"access_key": "{{user `aws_access_key`}}",
"ami_name": "{{ user `build_name` }}_{{ user `build_ref` }}_{{ user `build_id` }}",
"ami_regions": "{{ user `ami_regions` }}",
"associate_public_ip_address": true,
"instance_type": "t2.medium",
"region": "{{ user `aws_region` }}",
"secret_key": "{{user `aws_secret_key`}}",
"security_group_id": "{{ user `aws_security_group_id`}}",
"source_ami": "{{ user `source_ami` }}",
"ssh_private_ip": "false",
"ssh_username": "admin",
"subnet_id": "{{ user `aws_subnet_id` }}",
"type": "amazon-ebs",
"vpc_id": "{{ user `aws_vpc_id` }}",
"run_tags": {
"Name": "{{ user `build_name` }}_{{ user `build_ref` }}_{{ user `build_id` }}",
"packer-building": "true"
},
"tags": {
"build_name": "{{ user `build_name` }}",
"build_ref": "{{ user `build_ref` }}",
"build_id": "{{ user `build_id` }}"
}
}
],
"provisioners": [
{
"type": "shell",
"execute_command": "{{.Vars}} sudo -E bash '{{.Path}}'",
"inline": [
"sleep 15",
"DEBIAN_FRONTEND=noninteractive apt-get -y update",
"DEBIAN_FRONTEND=noninteractive apt-get -y -o Dpkg::Options::=\"--force-confdef\" -o Dpkg::Options::=\"--force-confold\" dist-upgrade",
"DEBIAN_FRONTEND=noninteractive apt-get -y -o Dpkg::Options::=\"--force-confdef\" -o Dpkg::Options::=\"--force-confold\" install build-essential python-dev libffi-dev libssl-dev libxml2-dev libxslt1-dev zlib1g-dev",
"DEBIAN_FRONTEND=noninteractive apt-get -y -o Dpkg::Options::=\"--force-confdef\" -o Dpkg::Options::=\"--force-confold\" --purge remove python-cffi",
"wget https://bootstrap.pypa.io/get-pip.py -O /usr/local/bin/get-pip.py",
"chmod +x /usr/local/bin/get-pip.py",
"python /usr/local/bin/get-pip.py",
"pip install ansible==2.4.2"
]
},
{
"type": "ansible-local",
"group_vars": "ansible/inventory/group_vars",
"playbook_dir": "ansible",
"playbook_file": "ansible/playbook.yml",
"extra_arguments": [
"-e ec2ami=true"
]
},
{
"type": "shell",
"execute_command": "{{.Vars}} sudo -E bash '{{.Path}}'",
"inline": [
"pip uninstall -y ansible httplib2 Jinja2 paramiko PyYAML six",
"apt-get -y purge python-dev python-pip libffi-dev libssl-dev libxml2-dev libxslt1-dev zlib1g-dev",
"apt-get -y autoremove --purge",
"apt-get -y clean",
"rm -rf /tmp ; mkdir /tmp ; chmod 1777 /tmp"
]
}
]
}