blob: 11c8208fa23a83843e987a3440d6bea9b71501e4 [file] [log] [blame]
Zack Williams5e2a5852016-03-10 12:45:48 -07001#!/usr/bin/env python
Zack Williams2eb97f92016-02-29 09:37:36 -07002
3import json
4import subprocess
5
6def dict_keys_dash_to_underscore(dashed):
7 underscored = dict((k.replace('-','_'),v) for k,v in dashed.items())
8 return underscored
9
10juju_status_json = subprocess.check_output("juju status --format=json", shell=True)
11juju_status = json.loads(juju_status_json)
12
13juju_machines = {}
14for index, data in juju_status['machines'].iteritems():
15 data_underscore = dict_keys_dash_to_underscore(data)
16 juju_machines[data_underscore["dns_name"]] = data_underscore
Zack Williamsf1fb0942016-02-29 14:48:01 -070017 juju_machines[data_underscore["dns_name"]]["machine_id"] = index
Zack Williams2eb97f92016-02-29 09:37:36 -070018
19print json.dumps({
20 "changed": True,
21 "ansible_facts" : {
22 "juju_enviromnment": juju_status['environment'],
23 "juju_machines": juju_machines,
Zack Williamsf1fb0942016-02-29 14:48:01 -070024 "juju_services": juju_status['services'],
Zack Williams2eb97f92016-02-29 09:37:36 -070025 },
26})
27