scottslowe-learning-tools/ansible-aws/create.yml
Scott S. Lowe b0a8f6de59 Commit learning environment for using Ansible with AWS
Add Ansible configuration, Ansible inventory, dynamic inventory script, and Ansible playbooks for a learning environment that shows how to manage AWS infrastructure using Ansible.

Signed-off-by: Scott S. Lowe <scott.lowe@scottlowe.org>
2016-10-23 10:09:49 -06:00

41 lines
1,002 B
YAML

---
- hosts: "localhost"
connection: "local"
gather_facts: false
vars:
ami: "<insert AMI ID here>"
region: "<insert AWS region here>"
type: "t2.micro"
sshkey: "<insert SSH keypair name here>"
vpcid: "<insert VPC ID here>"
tasks:
- name: "Create a new security group"
ec2_group:
name: "ansible-sec-group"
description: "New SG for Ansible-created instances"
region: "{{ region }}"
vpc_id: "{{ vpcid }}"
rules:
- proto: "tcp"
from_port: 22
to_port: 22
cidr_ip: "0.0.0.0/0"
rules_egress:
- proto: "all"
cidr_ip: "0.0.0.0/0"
register: secgrp
- name: "Provision an EC2 instance"
ec2:
key_name: "{{ sshkey }}"
group_id: "{{ secgrp.group_id }}"
instance_type: "{{ type }}"
ec2_region: "{{ region }}"
image: "{{ ami }}"
wait: true
count: 1
instance_tags:
tool: "ansible"
env: "test"
register: ec2instance