-
Notifications
You must be signed in to change notification settings - Fork 0
/
nodes_meshviewer
executable file
·45 lines (36 loc) · 1.09 KB
/
nodes_meshviewer
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
#!/usr/bin/env python3
#
# Dynamic inventory script for ansible
#
# $ ansible nodes -m sh_ping -i nodes_meshviewer
#
import urllib
import json
import os
import argparse
response = urllib.urlopen("https://events.ffhb.de/data/meshviewer.json")
body = response.read()
data = json.loads(body)
parser = argparse.ArgumentParser()
parser.add_argument('--list', action = 'store_true')
parser.add_argument('--host', action = 'store')
args = parser.parse_args()
inventory = {'_meta': {'hostvars': {}}}
if args.list:
inventory["nodes"] = {"hosts":[]}
for node in data['nodes']:
if not node["is_online"]:
continue
nodeid = node["node_id"]
if "breminale" not in node['firmware']['release']:
continue
inventory["nodes"]["hosts"].append(nodeid)
inventory["_meta"]["hostvars"][nodeid] = { }
for address in node["addresses"]:
if "2a06:8782:ffbb:" in address:
inventory["_meta"]["hostvars"][nodeid]["ansible_ssh_host"] = address
elif args.host:
for node in data['nodes']:
if node["node_id"] == args.host:
inventory = node
print json.dumps(inventory)