Adding hosts to inventory, adding data to existing hosts

I’m really new to Nornir and struggling. Originally I was going to use a csv file for my inventory on a Zero Touch Provisioning system. I figured this was a good opportunity to use Nornir. I converted my inventory to yaml and am able to initiate it and look at it. Having some issues though.

  1. I can add a host, but it doesn’t put that host in the hosts.yaml file after the fact. I don’t see a way to write it when done manipulating.

  2. My hosts.yaml file doesn’t have groups, and my data was very redudnant, so I want to add a group. I don’t see a way to do that in Nornir, but changing the .yaml another way seems a pain.

Any help is appreciated!

What exactly do you mean by 1. above? If you add the host to where?

For 2., if you are using SimpleInventory plugin, then you would have to create a “groups.yaml” file, and associate to the hosts via a “groups” dict entry (containing a list of one or more groups) in the hosts.yaml file. See for more details on the files that SimpleInventory needs.

Or are you trying to use a custom inventory?

I have writed a custom csv inventory plugins, may be it can help you.

A example csv file:

Hope this can help you and I think you will write your own plugin,it is not difficute.

Dear ericwu,

Can you please share the complete customized inventory plugin code?

I m new to Nornir, programming and trying to learn!

Hi Eric,

I’m also new to Nornir and python, can you share again your files? The link you posted in Github is no longer there. I’m trying to use a custom inventory and was looking for examples that I can use as reference. Thanks.