Skip to content

previous_nth_usable

Collection Note

This module is part of the ansible.utils collection. To install the collection, use:

ansible-galaxy collection install ansible.utils
Added in version 2.5.0.

Synopsis

  • This filter returns the previous nth usable ip within a network described by value.
  • Use previous_nth_usable to find the previous nth usable IP address in relation to another within a range

Parameters

Parameter Defaults / Choices Comments
offset
int
index value
previous nth usable IP address
value
str
required
subnets or individual address input for previous_nth_usable plugin

Examples

#### examples
- name: previous_nth_usable returns the second usable IP address for the given IP range
  debug:
    msg: "{{ '192.168.122.10/24' | ansible.utils.previous_nth_usable(2) }}"

- name: If there is no usable address, it returns an empty string.
  debug:
    msg: "{{ '192.168.122.1/24' | ansible.utils.previous_nth_usable(2) }}"

# TASK [previous_nth_usable returns the second usable IP address for the given IP range] **************************
# task path: /Users/amhatre/ansible-collections/playbooks/test_previous_nth_usable.yaml:9
# Loading collection ansible.utils from /Users/amhatre/ansible-collections/collections/ansible_collections/ansible/utils
# ok: [localhost] => {
#     "msg": "192.168.122.8"
# }
#
# TASK [If there is no usable address, it returns an empty string.] *******************************************
# task path: /Users/amhatre/ansible-collections/playbooks/test_previous_nth_usable.yaml:14
# Loading collection ansible.utils from /Users/amhatre/ansible-collections/collections/ansible_collections/ansible/utils
# ok: [localhost] => {
#     "msg": ""
# }

Return Values

Key Data Type Description Returned
data str Returns the previous nth usable ip within a network described by value.

Authors

  • Ashwini Mhatre (@amhatre)