@ -39,27 +39,37 @@ class InventoryScript(object):
self . groups = self . _parse ( )
self . groups = self . _parse ( )
def _parse ( self ) :
def _parse ( self ) :
all_hosts = { }
all_hosts = { }
self . raw = utils . parse_json ( self . data )
self . raw = utils . parse_json ( self . data )
all = Group ( ' all ' )
all = Group ( ' all ' )
groups = dict ( all = all )
groups = dict ( all = all )
group = None
group = None
if ' failed ' in self . raw :
raise errors . AnsibleError ( " failed to parse executable inventory script results " )
for ( group_name , data ) in self . raw . items ( ) :
for ( group_name , data ) in self . raw . items ( ) :
group = groups [ group_name ] = Group ( group_name )
group = groups [ group_name ] = Group ( group_name )
host = None
host = None
if not isinstance ( data , dict ) :
if not isinstance ( data , dict ) :
data = { ' hosts ' : data }
data = { ' hosts ' : data }
if ' hosts ' in data :
if ' hosts ' in data :
for hostname in data [ ' hosts ' ] :
for hostname in data [ ' hosts ' ] :
if not hostname in all_hosts :
if not hostname in all_hosts :
all_hosts [ hostname ] = Host ( hostname )
all_hosts [ hostname ] = Host ( hostname )
host = all_hosts [ hostname ]
host = all_hosts [ hostname ]
group . add_host ( host )
group . add_host ( host )
if ' vars ' in data :
if ' vars ' in data :
for k , v in data [ ' vars ' ] . iteritems ( ) :
for k , v in data [ ' vars ' ] . iteritems ( ) :
group . set_variable ( k , v )
group . set_variable ( k , v )
all . add_child_group ( group )
all . add_child_group ( group )
# Separate loop to ensure all groups are defined
# Separate loop to ensure all groups are defined
for ( group_name , data ) in self . raw . items ( ) :
for ( group_name , data ) in self . raw . items ( ) :
if isinstance ( data , dict ) and ' children ' in data :
if isinstance ( data , dict ) and ' children ' in data :