Ansible nxos_static_routes multiple destination address same next_hops

14 views
Skip to first unread message

Arnau Amargant Domene

unread,
May 27, 2021, 3:36:52 AM5/27/21
to Ansible Project
Hello,

Is there a way to have multiple destination address and the same next_hops? What I'm trying to do is shorten the lines of the playbook and better readability.

If you see the following image repeats the same next_hops for different address:

Screen Shot 2021-05-27 at 09.28.06.png 

What i would like to achive is something like:

- dest: 192.168.2.0/24192.168.4.0/24192.168.6.0/24
   next_hops:
    - interface: eth1/8
      forward_router_address: 20.0.0.5
    - interface: eth1/9
      forward_router_address: 20.0.0.13

But i dont know if its possible. 
Thanks.

Dick Visser

unread,
May 27, 2021, 3:56:16 AM5/27/21
to ansible...@googlegroups.com
If that next_hops list is going to be more or less static for many
destinations, a simple option would be to define it once and then
reference it.
Note that I had to manually type this - please post real text next
time, instead of pixel images, so people can copy/paste it, and things
can get indexed by search engines for the benefit of other people
having the same problems.


---
- name: Cisco stuff
cisco.nxos.nxos_static_routes:
config:
- afi: ipv4
routes:
- dest: 192.168.2.0/24
next_hops: "{{ default_next_hops }}"
- dest: 192.168.4.0/24
next_hops: "{{ default_next_hops }}"
- dest: 192.168.6.0/24
next_hops: "{{ default_next_hops }}"
vars:
default_next_hops:
- interface: eth1/8
forward_router_address: 20.0.0.5
- interface: eth1/9
forward_router_address: 20.0.0.13

You can also construct the entire config variable by looping over it.




On Thu, 27 May 2021 at 09:37, Arnau Amargant Domene <arna...@gmail.com> wrote:
>
> Hello,
>
> Is there a way to have multiple destination address and the same next_hops? What I'm trying to do is shorten the lines of the playbook and better readability.
>
> If you see the following image repeats the same next_hops for different address:
>
>
>
> What i would like to achive is something like:
>
> - dest: 192.168.2.0/24, 192.168.4.0/24, 192.168.6.0/24
> next_hops:
> - interface: eth1/8
> forward_router_address: 20.0.0.5
> - interface: eth1/9
> forward_router_address: 20.0.0.13
>
> But i dont know if its possible.
> Thanks.
>
> --
> You received this message because you are subscribed to the Google Groups "Ansible Project" group.
> To unsubscribe from this group and stop receiving emails from it, send an email to ansible-proje...@googlegroups.com.
> To view this discussion on the web visit https://groups.google.com/d/msgid/ansible-project/d08ee0b3-4a2c-44c0-846b-7ab6cf8bd214n%40googlegroups.com.



--
Dick Visser
Trust & Identity Service Operations Manager
GÉANT

Brian Coca

unread,
May 27, 2021, 12:48:42 PM5/27/21
to Ansible Project
Another option is to use YAML anchors, but variables are probably better.

- name: Cisco stuff
cisco.nxos.nxos_static_routes:
config:
- afi: ipv4
routes:
- dest: 192.168.2.0/24
next_hops: &hops
- interface: eth1/8
forward_router_address: 20.0.0.5
- interface: eth1/9
forward_router_address: 20.0.0.13
- dest: 192.168.4.0/24
next_hops: *hops
- dest: 192.168.6.0/24
next_hops: *hops

--
----------
Brian Coca

Reply all
Reply to author
Forward
0 new messages