Skip to content

Commit 3476929

Browse files
committed
Packer for AWS AMI πŸŽ‰
1 parent 7810982 commit 3476929

File tree

4 files changed

+76
-5
lines changed

4 files changed

+76
-5
lines changed

β€ŽREADME.md

+27-5
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,9 @@
22

33
Unmodified Postgres with some opinionated defaults and plugins.
44

5-
Packer & Ansible template that sets up a Digital Ocean snapshot of a PostgreSQL server with pre-installed and enabled goodies.
5+
Packer & Ansible templates that sets up a PostgreSQL server with pre-installed and enabled goodies in either of the following providers:
6+
- AWS (AMIs)
7+
- Digital Ocean (Snapshots)
68

79
## Supported Images
810
- Ubuntu 18.04 Bionic (LTS)
@@ -26,25 +28,45 @@ Packer & Ansible template that sets up a Digital Ocean snapshot of a PostgreSQL
2628

2729
## Walkthrough
2830

29-
1. Install the Ansible role `ANXS.postgresql`.
31+
### Install the Ansible role `ANXS.postgresql`.
3032
```
3133
$ ansible-galaxy install ANXS.postgresql -r tasks/install_roles.yml --force
3234
```
3335

34-
2. `DO_TOKEN`, `SNAPSHOT_NAME` and `REGION` all need to be defined. A list of valid Digital Ocean regions can be found [here](https://www.digitalocean.com/docs/platform/availability-matrix/).
36+
### For **Digital Ocean**
37+
- `DO_TOKEN`, `SNAPSHOT_NAME` and `REGION` all need to be defined. A list of valid Digital Ocean regions can be found [here](https://www.digitalocean.com/docs/platform/availability-matrix/).
3538
```
3639
$ export DO_TOKEN=your_digital_ocean_token
3740
$ export SNAPSHOT_NAME=your_snapshot_name
3841
$ export REGION=your_chosen_region
3942
```
4043

41-
3. Create the Digital Ocean snapshot
44+
- Create the Digital Ocean snapshot
4245
```
4346
$ packer build \
4447
-var "do_token=$DO_TOKEN" \
4548
-var "name=$SNAPSHOT_NAME" \
4649
-var "region=$REGION" \
47-
packer.json
50+
digitalOcean.json
51+
```
52+
53+
### For **AWS**
54+
- `AWS_ACCESS_KEY`, `AWS_SECRET_KEY`, `SNAPSHOT_NAME` and `REGION` all need to be defined. A list of valid AWS regions can be found [here](https://docs.aws.amazon.com/general/latest/gr/ec2-service.html).
55+
```
56+
$ export AWS_ACCESS_KEY=your_aws_access_key
57+
$ export AWS_SECRET_KEY=your_aws_secret_key
58+
$ export SNAPSHOT_NAME=your_snapshot_name
59+
$ export REGION=your_chosen_region
60+
```
61+
62+
- Create the AWS AMI
63+
```
64+
$ packer build \
65+
-var "aws_access_key=$AWS_ACCESS_KEY" \
66+
-var "aws_secret_key=$AWS_SECRET_KEY" \
67+
-var "name=$SNAPSHOT_NAME" \
68+
-var "region=$REGION" \
69+
amazon.json
4870
```
4971

5072
Once this is complete, you now have a snapshot available to use for any of your droplets.

β€Žamazon.json

+44
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
{
2+
"variables": {
3+
"aws_access_key": "",
4+
"aws_secret_key": "",
5+
"region": "",
6+
"name": ""
7+
},
8+
"builders": [{
9+
"type": "amazon-ebs",
10+
"access_key": "{{user `aws_access_key`}}",
11+
"secret_key": "{{user `aws_secret_key`}}",
12+
"region": "{{user `region`}}",
13+
"source_ami": "ami-0f7719e8b7ba25c61",
14+
"instance_type": "t2.micro",
15+
"ssh_username": "ubuntu",
16+
"ami_name": "{{user `name`}}",
17+
"launch_block_device_mappings": [{
18+
"device_name": "/dev/sda1",
19+
"encrypted": true,
20+
"kms_key_id": "44e7e739-21f1-4678-829e-d1ac63d121b4",
21+
"iops": 400,
22+
"volume_type": "io1",
23+
"volume_size": 8,
24+
"delete_on_termination": true
25+
26+
}]
27+
}],
28+
"provisioners": [
29+
{
30+
"type": "ansible",
31+
"playbook_file": "ansible/playbook.yml"
32+
},
33+
{
34+
"execute_command": "echo 'packer' | sudo -S sh -c '{{ .Vars }} {{ .Path }}'",
35+
"type": "shell",
36+
"scripts": [
37+
"scripts/01-test",
38+
"scripts/90-cleanup.sh",
39+
"scripts/91-log_cleanup.sh",
40+
"scripts/99-img_check.sh"
41+
]
42+
}
43+
]
44+
}

β€Žansible/tasks/setup-system.yml

+5
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,11 @@
44
apt: update_cache=yes upgrade=yes
55
# SEE http://archive.vn/DKJjs#parameter-upgrade
66

7+
- name: add universe repository for bionic
8+
apt_repository:
9+
repo: deb http://archive.ubuntu.com/ubuntu bionic universe
10+
state: present
11+
712
- name: Install essentials
813
apt:
914
pkg:
File renamed without changes.

0 commit comments

Comments
Β (0)