-
Notifications
You must be signed in to change notification settings - Fork 0
/
create_ec2_instance_playbook.yml
35 lines (33 loc) · 1.08 KB
/
create_ec2_instance_playbook.yml
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
- name: Deploy an EC2 instance in AWS
hosts: localhost
gather_facts: no
environment:
AWS_REGION: us-east-2
tasks:
- name: Create security group
amazon.aws.ec2_security_group:
name: sample-app-ansible
description: Allow HTTP and SSH traffic
rules:
- proto: tcp
ports: [8080]
cidr_ip: 0.0.0.0/0
- proto: tcp
ports: [22]
cidr_ip: 0.0.0.0/0
register: aws_security_group
- name: Create a new EC2 key pair
amazon.aws.ec2_key:
name: ansible-ch2
file_name: ansible-ch2.key
no_log: true
register: aws_ec2_key_pair
- name: Create EC2 instance with Amazon Linux 2003
amazon.aws.ec2_instance:
name: sample-app-ansible
key_name: "{{ aws_ec2_key_pair.key.name }}"
instance_type: t2.micro
security_group: "{{ aws_security_group.group_id }}"
image_id: ami-0900fe555666598a2
tags:
Ansible: ch2_instances