Replies: 2 comments
-
Ok, i did a better analysis of SimpleInventory plugin and it's more complicated that i initially thought (still trying to figure out inheritance). |
Beta Was this translation helpful? Give feedback.
-
If you need it a lot, I would recommend creating an inventory plugin. You would also have control over how you want to merge the data. Your code in the beginning is almost correct. Something like this should do the trick: from nornir.core.inventory import Host, ParentGroups
for device in customdata:
devicename = device['Name']
deviceos = device['DeviceOS']
nr.inventory.hosts[devicename] = Host(
name = devicename,
groups = ParentGroups([nr.inventory.groups[deviceos], nr.inventory.groups["scrapli"]]),
hostname = devicename,
) Hope that helps |
Beta Was this translation helpful? Give feedback.
-
Hi,
A probably tricky question for a newbie: Is there a way to have multiple inventories being active at the same time?
I want to have a SimpleInventory with a yaml file and another custom inventory created on the fly (from various xls files).
I have tried adding the custom inventory entries to the initial inventory, using the following code:
Probably i'm missing something obvious, because the following code returns the correct platform (which is defined in groups.yaml) for the SimpleInventory entries, but None as the platform for the custom inventory entries.
At the same time i can see all (SimpleInventory + custominventory) Host records are there.
If i also update the platform attribute like below, then everything "seems" fine (besides scrapli connection_options as expected, which is not an issue for the devices in the custom inventory).
This is the groups.yaml file.
I could guess a new plugin would be needed to support both input methods, but i was hoping to be able to cope around using the above workaround, unless i'm going to hit other issues.
Beta Was this translation helpful? Give feedback.
All reactions