cancel
Showing results for 
Search instead for 
Did you mean: 
cancel
Announcements

Community Helping Community

106
Views
0
Helpful
2
Replies
Beginner

Ansible - getting value of LAN interface

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?

2 REPLIES 2
VIP Advisor

Re: Ansible - getting value of LAN interface

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.

Everyone's tags (1)
Highlighted
Beginner

Re: Ansible - getting value of LAN interface

Thanks Seb, 

 

Will give it a try

CreatePlease to create content
Content for Community-Ad
July's Community Spotlight Awards