1
1
#!/usr/bin/env python
2
- ''' Dynamic inventory script for Ansible/Vagrant '''
2
+
3
3
import argparse
4
4
import json
5
5
import os
@@ -23,16 +23,16 @@ def build_inventory(host=None):
23
23
# build groups for a specific host
24
24
def _gather_groups (inventory , host ):
25
25
for group in host ['ansible_groups' ]:
26
- if not inventory . has_key ( group ) :
26
+ if group not in inventory :
27
27
inventory [group ] = {}
28
28
inventory [group ]['hosts' ] = []
29
29
inventory [group ]['vars' ] = {}
30
30
inventory [group ]['hosts' ].append (host ['name' ] + domain )
31
31
# append box version
32
32
box = sub (r"[/]" , "_" , config ['box' ])
33
- if host . has_key ( 'box' ) :
33
+ if 'box' in host :
34
34
box = sub (r"[/]" , "_" , host ['box' ])
35
- if not inventory . has_key ( box ) :
35
+ if box not in inventory :
36
36
inventory [box ] = {}
37
37
inventory [box ]['hosts' ] = []
38
38
inventory [box ]['vars' ] = {}
@@ -51,9 +51,9 @@ def main():
51
51
parser = setup_cli ()
52
52
args = parser .parse_args ()
53
53
if args .list :
54
- print json .dumps (build_inventory ())
54
+ print ( json .dumps (build_inventory () ))
55
55
elif args .host :
56
- print json .dumps (build_inventory (args .host ))
56
+ print ( json .dumps (build_inventory (args .host ) ))
57
57
else :
58
58
parser .print_help ()
59
59
0 commit comments