Ansible - Increment IP address

by
Jeremy Canfield |
Updated: June 06 2025
| Ansible articles
The ansible.utils.ipmath filter can be used to increment an IP address. The ipmath filter was added in version 5.1.2 of ansible.util. The ansible-galaxy collection list command can be used to determine if you have the ansible.utils collection installed, and if so, what version of the collection you have installed. Notice in this example that version 4.0.0 of the ansible.utils collection is installed.
~]# ansible-galaxy collection list
Collection Version
--------------------- -------
ansible.utils 4.0.0
community.general 8.5.0
The ansible-galaxy collection install command can be used to install version 5.1.2 or higher of ansible.utils.
ansible-galaxy collection install ansible.utils==5.1.2
And here is an example of how to increment an IP address.
---
- hosts: localhost
tasks:
- name: increment IP address +1
ansible.builtin.debug: "{{ '10.11.12.13 | ansible.utils.ipmath(1) }}"
...
Did you find this article helpful?
If so, consider buying me a coffee over at