Skip to content

Instantly share code, notes, and snippets.

@jackl0phty
Last active October 29, 2015 22:26
Show Gist options
  • Save jackl0phty/9605516bfddd017c9b3c to your computer and use it in GitHub Desktop.
Save jackl0phty/9605516bfddd017c9b3c to your computer and use it in GitHub Desktop.
Use Ansible to spin up an EC2 Instance With Least Privileges.
---
- hosts: localhost
connection: local
gather_facts: no
vars:
region: us-east-1
instance_type: t1.micro
ami: ami-d85e75b0
sg: sg-my-security-group
tasks:
- name: Spin up test server.
local_action:
module: ec2
region: "{{ region }}"
key_name: mykey-aws
instance_type: "{{ instance_type }}"
image: "{{ ami }}"
wait: yes
group_id: "{{ sg }}"
instance_tags:
Name: web01.example.com
env: prod
created_by: ansible
app: test
group: test
exact_count: 1
count_tag:
group: test
# Below is an IAM policy with the least privileges required to Create a new EC2 instance.
"Version": "2012-10-17",
"Statement": [
{
"Effect": "Allow",
"Action": [
"ec2:RunInstances"
],
"Resource": "*"
}
]
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment