-
Notifications
You must be signed in to change notification settings - Fork 5
/
createAnsibleHosts.py
executable file
·36 lines (29 loc) · 1.09 KB
/
createAnsibleHosts.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
#!/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 = []
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:
replica_set.append(instance.public_dns_name)
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()
print 'Written ./ansible-hosts'