cancel
Showing results for 
Search instead for 
Did you mean: 
cancel
2362
Views
0
Helpful
3
Replies

Ansible - getting value of LAN interface

illusion_rox
Level 1
Level 1

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?

3 Replies 3

Seb Rupik
VIP Alumni
VIP Alumni

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.

Thanks Seb, 

 

Will give it a try

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 }}