-
Notifications
You must be signed in to change notification settings - Fork 7
/
hosts_generator.py
executable file
·51 lines (42 loc) · 1.08 KB
/
hosts_generator.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
#!/usr/bin/env python3
import argparse
import json
import sys
import yaml
# Pick up our group_vars file
stream = open("group_vars/all", 'r')
vars = yaml.load(stream, Loader=yaml.FullLoader)
hosts = {
"chroot": {
"hosts": [
vars['chrootpath']
],
"vars": {
"ansible_connection": "chroot"
}
},
"builder": {
"hosts": [
"localhost"
],
"vars": {
"ansible_connection": "local"
}
}
}
def parse_args():
parser = argparse.ArgumentParser(description='Squashible inventory module')
group = parser.add_mutually_exclusive_group(required=True)
group.add_argument('--list', action='store_true',
help='List active servers')
group.add_argument('--host', help='List details about the specific host')
return parser.parse_args()
def main():
args = parse_args()
if args.list:
print(json.dumps(hosts, indent=2))
elif args.host:
print(json.dumps(hosts, indent=2))
sys.exit(0)
if __name__ == '__main__':
main()