-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathinv.py
More file actions
24 lines (18 loc) · 748 Bytes
/
inv.py
File metadata and controls
24 lines (18 loc) · 748 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
"""A small helper script for generating an Ansible inventory file based on the Pulumi stack outputs"""
import json
import sys
from jinja2 import Template
j = json.loads(sys.stdin.read())
all_nodes = j['masters'] + j['workers']
# Min cluster size is 3 nodes, in which case they all need to be etcd members
# otherwise just grab the first 3 nodes
if len(all_nodes) <= 3:
etcd_nodes = all_nodes
else:
etcd_nodes = all_nodes[:3]
with open('files/inventory.ini.j2', 'r') as f:
rendered = Template(f.read()).render(all=all_nodes,
masters=j['masters'],
workers=j['workers'],
etcd_nodes=etcd_nodes)
print(rendered)