Zack Williams | 2eb97f9 | 2016-02-29 09:37:36 -0700 | [diff] [blame] | 1 | #!/usr/bin/python |
| 2 | |
| 3 | import json |
| 4 | import subprocess |
| 5 | |
| 6 | def dict_keys_dash_to_underscore(dashed): |
| 7 | underscored = dict((k.replace('-','_'),v) for k,v in dashed.items()) |
| 8 | return underscored |
| 9 | |
| 10 | juju_status_json = subprocess.check_output("juju status --format=json", shell=True) |
| 11 | juju_status = json.loads(juju_status_json) |
| 12 | |
| 13 | juju_machines = {} |
| 14 | for 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 Williams | f1fb094 | 2016-02-29 14:48:01 -0700 | [diff] [blame] | 17 | juju_machines[data_underscore["dns_name"]]["machine_id"] = index |
Zack Williams | 2eb97f9 | 2016-02-29 09:37:36 -0700 | [diff] [blame] | 18 | |
| 19 | print json.dumps({ |
| 20 | "changed": True, |
| 21 | "ansible_facts" : { |
| 22 | "juju_enviromnment": juju_status['environment'], |
| 23 | "juju_machines": juju_machines, |
Zack Williams | f1fb094 | 2016-02-29 14:48:01 -0700 | [diff] [blame] | 24 | "juju_services": juju_status['services'], |
Zack Williams | 2eb97f9 | 2016-02-29 09:37:36 -0700 | [diff] [blame] | 25 | }, |
| 26 | }) |
| 27 | |