Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Ansible: How to increment IP address?

I am passing a variable to Ansible with --extra-vars "lan=10.10.10.1".

I now need to increment this IPaddress so that the last octet is .2 so it will equal 10.10.10.2.

How would this be achieved in Ansible?

like image 778
user673906 Avatar asked Sep 01 '25 02:09

user673906


1 Answers

As of Ansible 2.7 this can be done using IP Math:

{{ lan | ipmath(1) }}
like image 199
Lars Francke Avatar answered Sep 02 '25 21:09

Lars Francke