blob: 70850e0bea06dbee83e67a5c8a67abcc0a290273 [file] [log] [blame]
Zack Williams2eb97f92016-02-29 09:37:36 -07001#!/usr/bin/python
2
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