-
Notifications
You must be signed in to change notification settings - Fork 0
/
rng-playbook.yml
85 lines (68 loc) · 2.22 KB
/
rng-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
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
# Use the ec2 module to create a new host and then add
# it to a special "ec2hosts" group.
- hosts: localhost
connection: local
gather_facts: False
vars:
keypair: "id_rsa"
instance_type: "t1.micro"
image: "ami-896c96fe"
group: "spray"
region: "eu-west-1"
zone: "eu-west-1a"
tasks:
- name: make one instance
ec2: image={{ image }}
instance_type={{ instance_type }}
keypair={{ keypair }}
instance_tags='{"foo":"bar"}'
region={{ region }}
group={{ group }}
wait=true
register: ec2_info
- debug: var=ec2_info
- debug: var=item
with_items: ec2_info.instance_ids
- add_host: hostname={{ item.public_ip }} groupname=ec2hosts
with_items: ec2_info.instances
- name: wait for instances to listen on port:22
wait_for:
state=started
host={{ item.public_dns_name }}
port=22
with_items: ec2_info.instances
# Connect to the node and gather facts,
# including the instance-id. These facts
# are added to inventory hostvars for the
# duration of the playbook's execution
# Typical "provisioning" tasks would go in
# this playbook.
- hosts: ec2hosts
gather_facts: True
user: ubuntu
sudo: True
tasks:
# fetch instance data from the metadata servers in ec2
- ec2_facts:
# show all known facts for this host
- debug: var=hostvars[inventory_hostname]
# just show the instance-id
- debug: msg="{{ hostvars[inventory_hostname]['ansible_ec2_instance_id'] }}"
# Using the instanceid, call the ec2 module
# locally to remove the instance by declaring
# it's state is "absent"
- hosts: ec2hosts
gather_facts: True
user: ubuntu
tags: deploy
sudo: True
tasks:
- ec2_facts:
- name: install java 7
apt: name=openjdk-7-jre state=latest install_recommends=no update_cache=yes
- name: copy the webapp
copy: src=./target/universal/rng-0.1.0.tgz dest=/opt/
- name: extract the webapp folder
command: chdir=/opt/ tar -xvzf rng-0.1.0.tgz
- name: start webapp
command: chdir=/opt/rng-0.1.0 /opt/rng-0.1.0/bin/rng -mem 512 -Drng.host.public_dns={{ hostvars[inventory_hostname]['ansible_ec2_public_hostname'] }}