Ansible - getting value of LAN interface
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-23-2019 01:41 AM
Hi all,
Is it possible to get the ip address of LAN interface dynamically from each router and then setting it up and ospf router id while running ansible script?
- Labels:
-
Network Management
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-23-2019 02:33 AM
Hi there,
Try the following playbook:
--- - name: set router id hosts: foo
connection: network_cli tasks: - name: get IP address ios_command: commands: "sh ip int br {{ interface }}" register: var_ip_addr - name: set OSPF router-id ios_config: lines: - "router-id {{ var_ip_addr.stdout[0].split('\n')[1].split()[1] }}" parents: "router ospf {{ pid }}" ...
You hosts.ini will need to look like:
[foo:vars] ansible_network_os=ios [foo] bar001 anisble_host=192.168.1.1 interface=vlan10 pid=0 bar001 anisble_host=192.168.1.2 interface=vlan10 pid=0 bar001 anisble_host=192.168.1.3 interface=vlan10 pid=0
I've been able to test the 'get ip address' task and confirm the multiple split commands return the IP address, but I don't have anything to test the 'set ospf router-id' task on...but that should work too :)
cheers,
Seb.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-23-2019 11:19 AM
Thanks Seb,
Will give it a try
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-24-2019 10:16 AM
Dear Seb,
Sorry returning to this post after sometime. Can you extend your support to advise from where we are getting the values for {{ interface }} and {{ pid }}
