netbox-community / ansible_modules

NetBox modules for Ansible using Ansible Collections
GNU General Public License v3.0
330 stars 213 forks source link

Use ansible facts to populate data? #25

Closed gardar closed 5 years ago

gardar commented 5 years ago

Are there any plans to have the option to gather data about a device with ansible facts and then use the facts to populate device/inventory data in netbox?

I'm sorry if this has already been discussed or if it's perhaps already possible, I only took a quick glance and it didn't seem like it's possible currently.

FragmentedPacket commented 5 years ago

This should already be possible as you would just pass the necessary data into the Netbox modules that are obtained from whatever fact gathering is done. There might have to be some data normalization that needs to happen to work with the modules, though.

gardar commented 5 years ago

Yes I understand that I can technically put what ever data I need into the netbox modules and use that, I was more curious if there would be an "official" way so to speak on the roadmap.

FragmentedPacket commented 5 years ago

Not at the moment. One of my colleagues is working on using Batfish to import data into Netbox using these modules, but nothing on the roadmap to be included within this repo.

Not sure when that project will be open sourced as it's still be developed, but you can watch the demonstration from NFD. NFD21 - Look at the Network to Code Network Automation Journey – Part 1.

If i'm off base on what you're asking, please provide an example!

gardar commented 5 years ago

Well not sure if you are off base but I'll explain what I'm asking a little better anyways.

What I'm trying to achieve is to use ansible to provide details about devices in netbox automatically, the way I see it is that at first ansible would connect to the device I want to add to netbox and gather facts about the device, then it would use those facts to create or update the device and the inventory items of the device. I'm looking into this from the point of view of servers, but I see networking devices would benefit from it too. In most cases the facts from ansible should be able to provide details about the name of the device, the operating system, cpu, ram, disk usage, network interfaces and ips, etc.

This would basically be the same thing ansible-cmdb does but it would populate the information in netbox rather than ansible-cmdb ( https://github.com/fboender/ansible-cmdb ) Another project to take a look at would be the netbox_agent ( https://github.com/Solvik/netbox_agent ) which does provide the data into netbox, but does require the agent set up on the servers, and as such won't be useful for networking devices.

FragmentedPacket commented 5 years ago

Thanks for the explanation and examples.

That is definitely not something this collection is looking to accomplish. It's just a way to use Ansible to populate Netbox via Ansible. It can definitely be used as an interface for such projects.

The furthest this collection will go away from that is inventory/lookup plugins.

cpmills1975 commented 5 years ago

Reading through the blog article on the new network features coming in Ansible 2.9, it might be worth looking in to whether these modules could take the, now standard, data structures that the Ansible network modules will produce/consume and record the details against a named device in Netbox.

remyd1 commented 2 years ago

This thread is a bit old, but I would need exactly the same kind of playbook using this module. It seems that there is no official way to do it even if it seems to be possible (I saw some stuff using this module with network device to gather device informations and import it using the netbox API).

Any news about it ?

gardar commented 2 years ago

This thread is a bit old, but I would need exactly the same kind of playbook using this module. It seems that there is no official way to do it even if it seems to be possible (I saw some stuff using this module with network device to gather device informations and import it using the netbox API).

Any news about it ?

I actually created my own Ansible role for this, but I have not made it public (yet). While the idea for the role sounds simple it turned out to be quite involved and I've still got a few things to iron out until I feel comfortable publishing it.

remyd1 commented 2 years ago

Ok. Please keep us inform about it. In the meantime, I created a basic python script to create a csv file for interfaces, but it is not really helpful...