Showing
1 changed file
with
5 additions
and
3 deletions
@@ -62,23 +62,25 @@ for _az in azs_mappings.keys(): | @@ -62,23 +62,25 @@ for _az in azs_mappings.keys(): | ||
62 | print("get all inventory info success. \n") | 62 | print("get all inventory info success. \n") |
63 | print(all_groups) | 63 | print(all_groups) |
64 | 64 | ||
65 | -## generate az inventory files | 65 | +# generate az inventory files |
66 | env = Environment(loader=PackageLoader('inventory')) | 66 | env = Environment(loader=PackageLoader('inventory')) |
67 | 67 | ||
68 | for _az in azs_mappings.keys(): | 68 | for _az in azs_mappings.keys(): |
69 | az = azs_mappings[_az] | 69 | az = azs_mappings[_az] |
70 | 70 | ||
71 | - #backup old file and open new file | 71 | + # backup old file and open new file |
72 | hosts = os.path.join("./inventories", az, "hosts") | 72 | hosts = os.path.join("./inventories", az, "hosts") |
73 | call("mv %s %s" % (hosts, os.path.join("./inventories", az, "hosts.bak")), shell=True) | 73 | call("mv %s %s" % (hosts, os.path.join("./inventories", az, "hosts.bak")), shell=True) |
74 | file = open(hosts, 'w') | 74 | file = open(hosts, 'w') |
75 | 75 | ||
76 | - #write template, sort the dict by key | 76 | + # write template, sort the dict by key |
77 | sorted_dict = collections.OrderedDict(sorted(all_groups[az].items(), key=lambda t: t[0])) | 77 | sorted_dict = collections.OrderedDict(sorted(all_groups[az].items(), key=lambda t: t[0])) |
78 | template = env.get_template('inventory-%s.j2' % az) | 78 | template = env.get_template('inventory-%s.j2' % az) |
79 | file.write(template.render(groups = sorted_dict )) | 79 | file.write(template.render(groups = sorted_dict )) |
80 | file.close() | 80 | file.close() |
81 | 81 | ||
82 | +print "success generate ansible inventory files ! ." | ||
83 | + | ||
82 | 84 | ||
83 | 85 | ||
84 | 86 |
-
Please register or login to post a comment