Skip to content

nthhost

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 nth host within a network described by value. To return the nth ip from a network, use the filter nthhost.
  • Nthhost also supports a negative value.

Parameters

Parameter Defaults / Choices Comments
query
str
nth host
value
str
required
The network address or range to test against.

Examples

#### examples
- name: To return the nth ip from a network, use the filter nthhost.
  debug:
    msg: "{{ '10.0.0.0/8' | ansible.utils.nthhost(305)  }}"

- name: nthhost also supports a negative value.
  debug:
    msg: "{{ '10.0.0.0/8' | ansible.utils.nthhost(-1) }}"

# TASK [To return the nth ip from a network, use the filter nthhost.] *****************************************
# task path: /Users/amhatre/ansible-collections/playbooks/test_nthhost.yaml:7
# Loading collection ansible.utils from /Users/amhatre/ansible-collections/collections/ansible_collections/ansible/utils
# ok: [localhost] => {
#     "msg": "10.0.1.49"
# }
#
# TASK [nthhost also supports a negative value.] **************************************************************
# task path: /Users/amhatre/ansible-collections/playbooks/test_nthhost.yaml:11
# Loading collection ansible.utils from /Users/amhatre/ansible-collections/collections/ansible_collections/ansible/utils
# ok: [localhost] => {
#     "msg": "10.255.255.255"
# }

Return Values

Key Data Type Description Returned
data str Returns nth host from network

Authors

  • Ashwini Mhatre (@amhatre)