...
|
...
|
@@ -62,23 +62,25 @@ for _az in azs_mappings.keys(): |
|
|
print("get all inventory info success. \n")
|
|
|
print(all_groups)
|
|
|
|
|
|
## generate az inventory files
|
|
|
# generate az inventory files
|
|
|
env = Environment(loader=PackageLoader('inventory'))
|
|
|
|
|
|
for _az in azs_mappings.keys():
|
|
|
az = azs_mappings[_az]
|
|
|
|
|
|
#backup old file and open new file
|
|
|
# backup old file and open new file
|
|
|
hosts = os.path.join("./inventories", az, "hosts")
|
|
|
call("mv %s %s" % (hosts, os.path.join("./inventories", az, "hosts.bak")), shell=True)
|
|
|
file = open(hosts, 'w')
|
|
|
|
|
|
#write template, sort the dict by key
|
|
|
# write template, sort the dict by key
|
|
|
sorted_dict = collections.OrderedDict(sorted(all_groups[az].items(), key=lambda t: t[0]))
|
|
|
template = env.get_template('inventory-%s.j2' % az)
|
|
|
file.write(template.render(groups = sorted_dict ))
|
|
|
file.close()
|
|
|
|
|
|
print "success generate ansible inventory files ! ."
|
|
|
|
|
|
|
|
|
|
|
|
|
...
|
...
|
|