-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathcreateAnsibleHostsServerPool.py
executable file
·65 lines (54 loc) · 1.9 KB
/
createAnsibleHostsServerPool.py
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
#!/usr/bin/env python2.7
from datetime import datetime, timedelta
import boto.ec2
conn = boto.ec2.connect_to_region("us-east-1")
keyname = "michael.lynn"
project = "Ops Manager Ansible"
opsmanager = ""
replica_set = []
serverpool = []
for r in conn.get_all_reservations(filters={"tag:project" : project}):
for instance in r.instances:
print instance.public_dns_name + " " + instance.state + " " + instance.key_name + " " + instance.instance_type + " " + instance.tags['Name']
if instance.key_name == keyname and instance.state == "running":
if instance.instance_type == "m3.xlarge":
opsmanager = instance.public_dns_name
else:
if instance.instance_type == 't2.small':
replica_set.append(instance.public_dns_name)
else:
if instance.instance_type == 't2.micro':
serverpool.append(instance.public_dns_name)
f = open('./ansible-hosts-serverpool', 'w')
f.write('[opsManager]\n')
f.write(opsmanager + " ansible_user=ec2-user\n")
f.write("\n")
f.write("[ReplicaSet]\n")
for machine in replica_set:
f.write(machine + " ansible_user=ec2-user\n")
f.write("\n")
f.write("[ReplicaSet:vars]\n")
f.write("opsmanagerurl=http://" + opsmanager + ":8080\n")
f.write("opsmanager=" + opsmanager + "\n")
f.write("\n")
f.write("[ServerPool]\n")
for machine in serverpool:
f.write(machine + " ansible_user=ec2-user\n")
f.write("\n")
f.write("[ServerPool:vars]\n")
f.write("opsmanagerurl=http://" + opsmanager + ":8080\n")
f.write("opsmanager=" + opsmanager + "\n")
f.close()
print 'Written ./ansible-hosts-serverpool'
f = open('./ansible-hosts', 'w')
f.write('[opsManager]\n')
f.write(opsmanager + " ansible_user=ec2-user\n")
f.write("\n")
f.write("[ReplicaSet]\n")
for machine in replica_set:
f.write(machine + " ansible_user=ec2-user\n")
f.write("\n")
f.write("[ReplicaSet:vars]\n")
f.write("opsmanagerurl=http://" + opsmanager + ":8080\n")
f.write("opsmanager=" + opsmanager + "\n")
f.close()