mirror of
https://github.com/ansible-collections/community.general.git
synced 2024-09-14 20:13:21 +02:00
[inventory/aos] Few fixes and small tweaks (#22259)
* Add ads server itself as an host in the inventory * Comment all value in example * Add Id in variable list per device * Centralize code to add device status to variables * Fix device variable name for blueprint
This commit is contained in:
parent
958ce4a252
commit
2376d891c7
2 changed files with 27 additions and 8 deletions
|
@ -8,12 +8,12 @@
|
|||
|
||||
[aos]
|
||||
|
||||
aos_server = 172.20.62.3
|
||||
port = 8888
|
||||
username = admin
|
||||
password = admin
|
||||
# aos_server = 172.20.62.3
|
||||
# port = 8888
|
||||
# username = admin
|
||||
# password = admin
|
||||
|
||||
# Blueprint Mode
|
||||
## Blueprint Mode
|
||||
# to use the inventory in mode Blueprint, you need to define the blueprint name you want to use
|
||||
|
||||
# blueprint = my-blueprint-l2
|
||||
|
|
|
@ -313,6 +313,12 @@ class AosInventory(object):
|
|||
# Save session information in variables of group all
|
||||
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
|
||||
# 2 modes are supported: device based or blueprint based
|
||||
|
@ -335,6 +341,13 @@ class AosInventory(object):
|
|||
if 'facts' in device.value.keys():
|
||||
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
|
||||
for node in bp.contents['system']['nodes']:
|
||||
if node['display_name'] == dev_name:
|
||||
|
@ -399,9 +412,7 @@ class AosInventory(object):
|
|||
self.add_host_to_group('all', device.name)
|
||||
|
||||
# populate information for this host
|
||||
if 'status' in device.value.keys():
|
||||
for key, value in device.value['status'].items():
|
||||
self.add_var_to_host(device.name, key, value)
|
||||
self.add_device_status_to_var(device.name, device)
|
||||
|
||||
if 'user_config' in device.value.keys():
|
||||
for key, value in device.value['user_config'].items():
|
||||
|
@ -543,6 +554,8 @@ class AosInventory(object):
|
|||
'ansible_ssh_host',
|
||||
device.value['facts']['mgmt_ipaddr'])
|
||||
|
||||
self.add_var_to_host(device_name,'id', device.id)
|
||||
|
||||
# self.add_host_to_group('all', device.name)
|
||||
for key, value in device.value['facts'].items():
|
||||
self.add_var_to_host(device_name, key, value)
|
||||
|
@ -564,6 +577,12 @@ class AosInventory(object):
|
|||
|
||||
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
|
||||
if __name__ == '__main__':
|
||||
AosInventory()
|
||||
|
|
Loading…
Reference in a new issue