@ -313,6 +313,12 @@ class AosInventory(object):
# Save session information in variables of group all
# Save session information in variables of group all
self . add_var_to_group ( ' all ' , ' aos_session ' , aos . session )
self . add_var_to_group ( ' all ' , ' aos_session ' , aos . session )
# Add the AOS server itself in the inventory
self . add_host_to_group ( " all " , ' aos ' )
self . add_var_to_host ( " aos " , " ansible_ssh_host " , self . aos_server )
self . add_var_to_host ( " aos " , " ansible_ssh_pass " , self . aos_password )
self . add_var_to_host ( " aos " , " ansible_ssh_user " , self . aos_username )
# ----------------------------------------------------
# ----------------------------------------------------
# Build the inventory
# Build the inventory
# 2 modes are supported: device based or blueprint based
# 2 modes are supported: device based or blueprint based
@ -335,6 +341,13 @@ class AosInventory(object):
if ' facts ' in device . value . keys ( ) :
if ' facts ' in device . value . keys ( ) :
self . add_device_facts_to_var ( dev_name , device )
self . add_device_facts_to_var ( dev_name , device )
# Define admin State and Status
if ' user_config ' in device . value . keys ( ) :
if ' admin_state ' in device . value [ ' user_config ' ] . keys ( ) :
self . add_var_to_host ( dev_name , ' admin_state ' , device . value [ ' user_config ' ] [ ' admin_state ' ] )
self . add_device_status_to_var ( dev_name , device )
# Go over the contents data structure
# Go over the contents data structure
for node in bp . contents [ ' system ' ] [ ' nodes ' ] :
for node in bp . contents [ ' system ' ] [ ' nodes ' ] :
if node [ ' display_name ' ] == dev_name :
if node [ ' display_name ' ] == dev_name :
@ -399,9 +412,7 @@ class AosInventory(object):
self . add_host_to_group ( ' all ' , device . name )
self . add_host_to_group ( ' all ' , device . name )
# populate information for this host
# populate information for this host
if ' status ' in device . value . keys ( ) :
self . add_device_status_to_var ( device . name , device )
for key , value in device . value [ ' status ' ] . items ( ) :
self . add_var_to_host ( device . name , key , value )
if ' user_config ' in device . value . keys ( ) :
if ' user_config ' in device . value . keys ( ) :
for key , value in device . value [ ' user_config ' ] . items ( ) :
for key , value in device . value [ ' user_config ' ] . items ( ) :
@ -543,6 +554,8 @@ class AosInventory(object):
' ansible_ssh_host ' ,
' ansible_ssh_host ' ,
device . value [ ' facts ' ] [ ' mgmt_ipaddr ' ] )
device . value [ ' facts ' ] [ ' mgmt_ipaddr ' ] )
self . add_var_to_host ( device_name , ' id ' , device . id )
# self.add_host_to_group('all', device.name)
# self.add_host_to_group('all', device.name)
for key , value in device . value [ ' facts ' ] . items ( ) :
for key , value in device . value [ ' facts ' ] . items ( ) :
self . add_var_to_host ( device_name , key , value )
self . add_var_to_host ( device_name , key , value )
@ -564,6 +577,12 @@ class AosInventory(object):
return clean_group
return clean_group
def add_device_status_to_var ( self , device_name , device ) :
if ' status ' in device . value . keys ( ) :
for key , value in device . value [ ' status ' ] . items ( ) :
self . add_var_to_host ( device . name , key , value )
# Run the script
# Run the script
if __name__ == ' __main__ ' :
if __name__ == ' __main__ ' :
AosInventory ( )
AosInventory ( )