How to fill netplan config file with routes via ansible

I’m trying to manage netplan by using ansible. That worked well in the past, where I used the a static template. Now I have to add several lines to the route section:

… bridges:… br0:
… routes:
… - to: 0.0.0.0/0
… via: {{ ansible_default_ipv4.gateway }}
… on-link: true
… - to: {{ IP1 }}/32
… scope: link
… - to: {{ IP2 }}/32
… scope: link
… …

Now here comes the part, where I struggle.

Due to the fact, that my local routes differs from host to host, I can’t use a static template. So I tried to create a list in the host vars file, that contains a list of ips.

ROUTES:

  • ip: “aaa.AAA.aaa.AAA”
  • ip: “bbb.BBB.bbb.BBB”
  • ip: “ccc.CCC.ccc.CCC”
  • ip: n

I wanted to insert this list into my netplan file while looping over this list.

But I dont get it working. Do you have any hint or advice?

Thx in advance

Markus