Skip to content
This repository was archived by the owner on Feb 14, 2022. It is now read-only.

Commit 08a44a5

Browse files
committed
closing #1 - switch to loading config from config json and using envvar.
1 parent 4f27173 commit 08a44a5

File tree

2 files changed

+26
-7
lines changed

2 files changed

+26
-7
lines changed

ambari/ansible-inventory-config.json

+14
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
{
2+
"cluster0": {
3+
"uri": "http://localhost:8080",
4+
"name": "cluster0",
5+
"ambari_user": "admin",
6+
"ambari_pass": "admin0"
7+
},
8+
"cluster1": {
9+
"uri": "https://localhost.localdomain:8444",
10+
"name": "cluster1",
11+
"ambari_user": "admin",
12+
"ambari_pass": "admin1"
13+
}
14+
}

ambari/ansible-inventory.py

+12-7
Original file line numberDiff line numberDiff line change
@@ -14,15 +14,20 @@
1414
class AmbariInventory(object):
1515

1616
def __init__(self):
17-
# TODO: load settings from a config file
18-
self.cluster_name = 'sandbox'
19-
self.uri = 'http://localhost:8080'
20-
self.ambari_user = 'admin'
21-
self.ambari_pass = 'admin'
17+
# Get the cluster name from the OS environment variable AMBARI_CLUSTER_NAME
18+
self.cluster_name = os.environ['AMBARI_CLUSTER_NAME']
19+
20+
# Load configuration file
21+
with open('ansible-inventory-config.json') as json_data_file:
22+
config = json.load(json_data_file)
23+
24+
self.uri = config[self.cluster_name]['uri']
25+
self.ambari_user = config[self.cluster_name]['ambari_user']
26+
self.ambari_pass = config[self.cluster_name]['ambari_pass']
2227

2328
args = self.process_args()
24-
service_list = self.get_service_list()
25-
#service_list = json.load(open('ansible-inventory-sample.json'))
29+
#service_list = self.get_service_list()
30+
service_list = json.load(open('ansible-inventory-sample.json'))
2631

2732
ambari_inv = self.generate_ambari_inventory(service_list)
2833

0 commit comments

Comments
 (0)