-
Notifications
You must be signed in to change notification settings - Fork 1
/
dynamic.py
58 lines (46 loc) · 1.74 KB
/
dynamic.py
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
46
47
48
49
50
51
52
53
54
55
56
57
#!/usr/bin/env python
import os
import argparse
import sys
try:
import json
except ImportError:
import simplejson as json
class OurInventory(object):
def __init__(self):
self.inventory = {}
self.read_cli_args()
if self.args.list:
self.inventory = self.our_inventory()
elif self.args.host:
self.inventory = self.empty_inventory()
else:
self.inventory = self.empty_inventory()
print json.dumps(self.inventory)
def our_inventory(self):
return {
'group': {
'hosts' : [ 'ansible-node1','ansible-node2' ],
'vars' : {
'ansible_user' : 'ansible'
}
},
'_meta' : {
'hostvars' : {
'ansible-node1' : {
'home_dir' : '/home/ansible'
},
'ansible-node2' : {
'home_dir' : '/home/ansible'
}
}
}
}
def empty_inventory(self):
return { '_meta' : { 'hostvars' : {} } }
def read_cli_args(self):
parser = argparse.ArgumentParser()
parser.add_argument('--list', action='store_true')
parser.add_argument('--host', action='store')
self.args = parser.parse_args()
OurInventory()