Add up Ansible variable in Jinja2 template
Have a look at the ipaddr
filter:
gateway: "{{ network_address | ipaddr('1') | ipaddr('address') }}"
Solution without ipaddr
filter:
{{ gateway.split('.')[:3] | join('.') + '.' + (gateway.split('.')[3] | int + 1) | string }}
But you can't do this:
addvlan:
- vlan: pruebavlan
address: 192.168.10.0
mask: 25
gateway: "{{ << address manipulations here >> }}"
tag: 1917
This will give you recursion error, because you try to define keys of addvlan.vlan
referencing other keys from same dict.
Do manipulations in your JSON template instead:
...
"address": "{{ address }}",
"mask": "{{ mask }}",
"gateway": "{{ address.split('.')[:3] | join('.') + '.' + (address.split('.')[3] | int + 1) | string }}",
"tag": "{{ tag }}",
...