Hi All,
This may better be suited to the database forum but since it's about integration, I've left it here.
We use Ansible every now and then for certain configuration rollouts and information gathering. Currently we have an inventory file setup that links hostnames to IP addresses. The problem with this is it requires manual changes whenever hostnames or IP addresses change, get added or deleted. We have over 500 Cisco IOS and NXOS devices in this list and so it isn't always accurate which can cause issues.
I am trying to work out if there is a way to extract hostnames and management IP addresses from the NeDi database into a file that is either already in the correct format, or can be manipulated through some other means to then be in the correct format, for the Ansible inventory file.
My first hurdle is figuring out how to get the IP address in a DB query to show as a proper IP. Currently they look like '180432786' or such.
Then I need to get the output of a query that gives hostname and IP to look like:
<hostname> ansible_host=<x.x.x.x> mgt_ip=<x.x.x.x>
And then order and group the hosts into sites. The inventory file is structured like this:
[network:children]
<site1>
<site2>
<site3>
[site1:children]
site1_core
site1_distribution
site1_access
[site1_core]
<site1_core_switch1 hostname> ansible_host=<x.x.x.x> mgt_ip=<x.x.x.x>
[site1_distribution]
<site1_distribution_switch1 hostname> ansible_host=<x.x.x.x> mgt_ip=<x.x.x.x>
[site1_access]
<site1_access_switch1 hostname> ansible_host=<x.x.x.x> mgt_ip=<x.x.x.x>
<site1_access_switch2 hostname> ansible_host=<x.x.x.x> mgt_ip=<x.x.x.x>
etc
I really hope someone has some tips for me with this! I think if I can get the output of a database query to give me hostnames and IP's, ordered by hostname alphabetically, that would be a good start. Then I can try and manipulate this data through some other method to order it and add the text required for ansible inventory file.