Skip to content
This repository was archived by the owner on Jan 21, 2020. It is now read-only.

Commit 599ee8b

Browse files
author
David Chung
committed
example aws playbook
Signed-off-by: David Chung <[email protected]>
1 parent 46d0977 commit 599ee8b

File tree

5 files changed

+161
-0
lines changed

5 files changed

+161
-0
lines changed

examples/playbooks/aws/README.md

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
Example Playbook for AWS
2+
========================
3+
4+
This playbook contains example of working with AWS. There are commands for
5+
starting up infrakit (which assumes you have used AWS CLI on your local computer and
6+
the `.aws/credentials` file exists) and commands for spinning up an on-demand or
7+
spot instance configured with Docker, Git and Go compiler.
8+
9+
## Adding this playbook
10+
11+
Adding files locally:
12+
13+
```
14+
infrakit playbook add aws file://$(pwd)/index.yml
15+
```
16+
17+
Adding the playbook from Github:
18+
19+
```
20+
infrakit playbook add aws https://raw.githubusercontent.com/docker/infrakit/master/examples/playbooks/aws/index.yml
21+
```

examples/playbooks/aws/index.yml

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
2+
# Start infrakit
3+
start : start.sh
4+
5+
# Create a single instance
6+
ondemand : provision-instance.yml
7+
8+
# Create a spot instance
9+
spot : provision-spot-instance.yml
Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
{{/* Input to create instance using the AWS instance plugin */}}
2+
{{/* =% instanceProvision `aws/ec2-instance` %= */}}
3+
4+
{{ $user := flag "user" "string" "username" | prompt "Please enter your user name:" "string" (env "USER")}}
5+
{{ $project := flag "project" "string" "project" | prompt "Project?" "string" "myproject" }}
6+
{{ $imageId := flag "image-id" "string" "Image ID" | prompt "AMI?" "string" "ami-df8406b0" }}
7+
{{ $instanceType := flag "instance-type" "string" "instance type" | prompt "Instance type?" "string" "t2.micro" }}
8+
{{ $privateIp := flag "private-ip" "string" "Private IP" | prompt "Private IP address (IPv4)?" "string" "172.31.20.100" }}
9+
10+
11+
{{ $keyName := flag "key" "string" "ssh key name" | prompt "SSH key?" "string" "infrakit"}}
12+
{{ $az := flag "az" "string" "availability zone" | prompt "Availability zone?" "string" "eu-central-1b"}}
13+
{{ $subnetId := flag "subnet" "string" "subnet id" | prompt "Subnet ID?" "string" "subnet-11b8376a" }}
14+
{{ $securityGroupId := flag "security-group-id" "string" "security group id" | prompt "Security group ID?" "string" "sg-975500fe" }}
15+
16+
Tags:
17+
infrakit.scope: {{ $project }}
18+
infrakit.created: {{ now | htmlDate }}
19+
infrakit.user: {{ $user }}
20+
21+
Init: |
22+
#!/bin/bash
23+
sudo add-apt-repository ppa:gophers/archive
24+
sudo apt-get update -y
25+
sudo apt-get install -y wget curl git golang-1.9-go
26+
wget -qO- https://get.docker.com | sh
27+
ln -s /usr/lib/go-1.9/bin/go /usr/local/bin/go
28+
29+
Properties:
30+
RunInstancesInput:
31+
BlockDeviceMappings: null
32+
DisableApiTermination: null
33+
EbsOptimized: null
34+
IamInstanceProfile: null
35+
ImageId: {{ $imageId }}
36+
InstanceInitiatedShutdownBehavior: null
37+
InstanceType: {{ $instanceType }}
38+
KeyName: {{ $keyName }}
39+
NetworkInterfaces:
40+
- AssociatePublicIpAddress: true
41+
PrivateIpAddress: {{ $privateIp }}
42+
DeleteOnTermination: true
43+
DeviceIndex: 0
44+
Groups:
45+
- {{ $securityGroupId }}
46+
NetworkInterfaceId: null
47+
SubnetId: {{ $subnetId }}
48+
Placement:
49+
Affinity: null
50+
AvailabilityZone: {{ $az }}
51+
Tenancy: null
52+
RamdiskId: null
53+
SubnetId: null
54+
UserData: null
55+
Tags:
56+
infrakit.user: {{ $user }}
Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
{{/* Input to create a spot instance using the AWS instance plugin */}}
2+
{{/* =% instanceProvision `aws/ec2-spot-instance` %= */}}
3+
4+
{{ $user := flag "user" "string" "username" | prompt "Please enter your user name:" "string" (env "USER")}}
5+
{{ $project := flag "project" "string" "project" | prompt "Project?" "string" "myproject" }}
6+
{{ $imageId := flag "image-id" "string" "Image ID" | prompt "AMI?" "string" "ami-df8406b0" }}
7+
{{ $instanceType := flag "instance-type" "string" "instance type" | prompt "Instance type?" "string" "t2.micro" }}
8+
{{ $privateIp := flag "private-ip" "string" "Private IP" | prompt "Private IP address (IPv4)?" "string" "172.31.20.100" }}
9+
{{ $spotPrice := flag "spot-price" "string" "Spot price" | prompt "Spot price?" "string" "0.03" }}
10+
11+
{{ $keyName := flag "key" "string" "ssh key name" | prompt "SSH key?" "string" "infrakit"}}
12+
{{ $az := flag "az" "string" "availability zone" | prompt "Availability zone?" "string" "eu-central-1b"}}
13+
{{ $subnetId := flag "subnet" "string" "subnet id" | prompt "Subnet ID?" "string" "subnet-11b8376a" }}
14+
{{ $securityGroupId := flag "security-group-id" "string" "security group id" | prompt "Security group ID?" "string" "sg-975500fe" }}
15+
16+
Tags:
17+
infrakit.scope: {{ $project }}
18+
infrakit.created: {{ now | htmlDate }}
19+
infrakit.user: {{ $user }}
20+
21+
Init: |
22+
#!/bin/bash
23+
sudo add-apt-repository ppa:gophers/archive
24+
sudo apt-get update -y
25+
sudo apt-get install -y wget curl git golang-1.9-go
26+
wget -qO- https://get.docker.com | sh
27+
ln -s /usr/lib/go-1.9/bin/go /usr/local/bin/go
28+
29+
Properties:
30+
RequestSpotInstancesInput:
31+
LaunchSpecification:
32+
ImageId: {{ $imageId }}
33+
InstanceType: {{ $instanceType }}
34+
KeyName: infrakit
35+
NetworkInterfaces:
36+
- AssociatePublicIpAddress: true
37+
DeleteOnTermination: true
38+
DeviceIndex: 0
39+
Groups:
40+
- {{ $securityGroupId }}
41+
NetworkInterfaceId: null
42+
PrivateIpAddress: {{ $privateIp }}
43+
PrivateIpAddresses: null
44+
SecondaryPrivateIpAddressCount: null
45+
SubnetId: {{ $subnetId }}
46+
Placement:
47+
AvailabilityZone: {{ $az }}
48+
SpotPrice: "{{ $spotPrice }}"
49+
Type: one-time

examples/playbooks/aws/start.sh

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
{{/* =% sh %= */}}
2+
3+
{{ $profile := flag "aws-cred-profile" "string" "Profile name" | prompt "Profile for your .aws/credentials?" "string" "default" }}
4+
{{ $region := flag "region" "string" "aws region" | prompt "Region?" "string" "eu-central-1"}}
5+
{{ $project := flag "project" "string" "project name" | prompt "Project?" "string" "myproject" }}
6+
7+
echo "Starting infrakit with aws plugin..."
8+
9+
{{/* Pick a credential from the local user's ~/.aws folder. You should have this if you use awscli. */}}
10+
{{ $creds := (source (cat "file://" (env "HOME") "/.aws/credentials" | nospace) | iniDecode | k $profile ) }}
11+
FOUND="{{ not (empty $creds) }}"
12+
13+
if [ $FOUND = "false" ]; then
14+
echo "no credentials found. bye"
15+
exit 1
16+
fi
17+
18+
{{ echo "Found your credential for profile" $profile }}
19+
20+
AWS_ACCESS_KEY_ID={{ $creds.aws_access_key_id }} \
21+
AWS_SECRET_ACCESS_KEY={{ $creds.aws_secret_access_key }} \
22+
INFRAKIT_AWS_REGION={{ $region }} \
23+
INFRAKIT_AWS_STACK_NAME={{ $project }} \
24+
INFRAKIT_AWS_NAMESPACE_TAGS="infrakit.scope={{ $project }}" \
25+
INFRAKIT_AWS_MONITOR_POLL_INTERVAL=5s \
26+
infrakit plugin start aws

0 commit comments

Comments
 (0)