-
Notifications
You must be signed in to change notification settings - Fork 1
/
aws_build.yml
96 lines (86 loc) · 2.81 KB
/
aws_build.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
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
---
- name: Provision an EC2 Instance
hosts: local
connection: local
gather_facts: False
tags: provisioning
# Necessary Variables for creating/provisioning the EC2 Instance
vars:
security_group: splunk-server-open # Change the security group name here
image: ami-3ecc8f46 # This is an AMI i created myself
count: 1
# Task that will be used to Launch/Create an EC2 Instance
tasks:
- name: Create Splunk Server Restricted Security Group
local_action:
module: ec2_group
name: splunk-server-restricted
description: Splunk Server Restricted Security Group
region: "{{ region }}"
rules:
- proto: tcp
from_port: 22
to_port: 22
cidr_ip:
- 192.168.0.0/16
- 10.0.0.0/8
- proto: tcp
from_port: 8000
to_port: 8000
cidr_ip:
- 192.168.0.0/16
- 10.0.0.0/8
rules_egress:
- proto: all
cidr_ip: 0.0.0.0/0
- name: Create Splunk Server Open Security Group
local_action:
module: ec2_group
name: splunk-server-open
description: Splunk Server Open Security Group
region: "{{ region }}"
rules:
- proto: tcp
from_port: 22
to_port: 22
cidr_ip: 0.0.0.0/0
- proto: tcp
from_port: 8000
to_port: 8000
cidr_ip: 0.0.0.0/0
rules_egress:
- proto: all
cidr_ip: 0.0.0.0/0
- name: Launch ec2 Instance
local_action: ec2
group={{ security_group }}
instance_type={{ instance_type}}
image={{ image }}
wait=true
region={{ region }}
keypair={{ keypair }}
count={{count}}
volumes:
- device_name: /dev/sdb
volume_type: gp2
volume_size: 100
delete_on_terminatin: true
register: ec2
- name: Add the newly created EC2 instance(s) to the local host group (located inside the directory)
local_action: lineinfile
dest="./hosts"
regexp={{ item.public_ip }}
insertafter="[splunk]" line={{ item.public_ip }}
with_items: "{{ec2.instances}}"
- name: Wait for SSH to come up
local_action: wait_for
host={{ item.public_ip }}
port=22
state=started
with_items: "{{ec2.instances}}"
- name: Add tag to Instance(s)
local_action: ec2_tag resource={{ item.id }} region={{ region }} state=present
with_items: "{{ec2.instances}}"
args:
tags:
Name: splunk