-
Notifications
You must be signed in to change notification settings - Fork 0
/
ec2-sample.yml
60 lines (56 loc) · 1.76 KB
/
ec2-sample.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
# Launch instances, runs some tasks
# and then terminate them
- name: Create a sandbox instance
hosts: localhost
connection: local
gather_facts: False
vars:
instance_type: t2.micro
vars_files:
- vars/ec2_vars.yml
tasks:
- name: Launch instance
ec2:
group: "{{ security_group }}"
instance_type: "{{ instance_type }}"
image: "{{ aws_linux_image }}"
wait: true
vpc_subnet_id: "{{ vpc_subnet_id }}"
key_name: "{{ key_name }}"
region: "{{ region }}"
assign_public_ip: yes
volumes:
- device_name: /dev/xvda
volume_type: gp2
volume_size: "{{ root_volume_size }}"
register: ec2
- name: Add new instance to host group
local_action: add_host hostname={{ item.public_ip }} groupname=launched
with_items: ec2.instances
- name: Wait for SSH to come up
local_action: wait_for host={{ item.public_dns_name }} port=22 delay=60 timeout=640 state=started
with_items: ec2.instances
- name: Pause 1 minute
pause: minutes=1
- name: Add to known hosts
local_action: command sh -c 'ssh-keyscan -t rsa {{ item.public_ip }} >>$HOME/.ssh/known_hosts'
with_items: ec2.instances
- name: Install Splunk
hosts: launched
remote_user: ec2-user
sudo: yes
gather_facts: False
vars:
splunk_src: "{{ lookup('env','HOME') }}/splunk-6.3.1-f3e41e4b37b2-linux-2.6-x86_64.rpm"
tasks:
- name: Copy Splunk binary
copy: src={{ splunk_src }} dest=/tmp/splunk.rpm
- name: Install Splunk RPM
yum: name=/tmp/splunk.rpm state=present
- name: Create Splunk Init script
command: /opt/splunk/bin/splunk enable boot-start -user splunk --accept-license
args:
creates: /etc/init.d/splunk
- name: Start Splunk
service: name=splunk state=started
# vim:ft=ansible: