-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsample_playbook.yml
More file actions
55 lines (51 loc) · 1.51 KB
/
sample_playbook.yml
File metadata and controls
55 lines (51 loc) · 1.51 KB
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
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
---
- hosts: controllerBox
vars_files:
- credentials.yml
vars:
tags: '{"Name":"sample_instance"}'
tasks:
- name: Create Security group
ec2_group:
aws_secret_key: "{{ aws_secret_key }}"
aws_access_key: "{{ aws_access_key }}"
name: "sample"
description: "security rules for sample_instance"
vpc_id: "vpc-f720e893"
region: "us-east-1"
- name: Spin up instance
ec2:
aws_secret_key: "{{ aws_secret_key }}"
aws_access_key: "{{ aws_access_key }}"
region: "us-east-1"
image: "ami-2051294a"
instance_type: "t2.micro"
instance_tags: "{{ tags }}"
count_tag: "{{ tags }}"
exact_count: 1
assign_public_ip: yes
group: sample
wait: yes
key_name: "sharedKey"
vpc_subnet_id: subnet-86167fde
register: created_instances
- name: Add host to the group
add_host:
hostname="{{ item.public_dns_name }}"
groupname="webServers"
instance_tags="{{ item.tags }} "
ansible_user=ec2-user
ansible_ssh_host="{{item.public_dns_name}}"
ansible_ssh_port=22
ansible_ssh_private_key_file=".keys/sharedKey.pem"
with_items: created_instances.tagged_instances
- name: Wait for SSH to come up
wait_for:
host="{{ item.public_dns_name }}"
port=22
state=started
with_items: created_instances.tagged_instances
- hosts: webServers
become: yes
roles:
- webServer