Skip to content

Commit

Permalink
Add use_range parameter to nios_next_ip (#200)
Browse files Browse the repository at this point in the history
This parameter add use_range parameter to nios_next_ip lookup plugin.
With this parameter set to true, the plugin will return first available
IP from the network range, assigned to the network.

Signed-off-by: Ondra Machacek <[email protected]>
  • Loading branch information
machacekondra authored May 29, 2024
1 parent 8bf75a1 commit 8b4f2d0
Showing 1 changed file with 12 additions and 1 deletion.
13 changes: 12 additions & 1 deletion plugins/lookup/nios_next_ip.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,11 @@
description: The CIDR network to retrieve the next address(es) from.
required: True
type: str
use_range:
description: Use DHCP range to retrieve the next available IP address(es).
required: false
default: no
type: bool
num:
description: The number of IP address(es) to return.
required: false
Expand All @@ -45,6 +50,10 @@
ansible.builtin.set_fact:
ipaddr: "{{ lookup('infoblox.nios_modules.nios_next_ip', '192.168.10.0/24', provider={'host': 'nios01', 'username': 'admin', 'password': 'password'}) }}"
- name: return next available IP address for network 192.168.10.0/24 from DHCP range
ansible.builtin.set_fact:
ipaddr: "{{ lookup('infoblox.nios_modules.nios_next_ip', '192.168.10.0/24', use_range=true, provider={'host': 'nios01', 'username': 'admin', 'password': 'password'}) }}"
- name: return next available IP address for network 192.168.10.0/24 in a non-default network view
ansible.builtin.set_fact:
ipaddr: "{{ lookup('infoblox.nios_modules.nios_next_ip', '192.168.10.0/24', network_view='ansible', \
Expand Down Expand Up @@ -91,7 +100,9 @@ def run(self, terms, variables=None, **kwargs):
provider = kwargs.pop('provider', {})
wapi = WapiLookup(provider)

if isinstance(ipaddress.ip_network(network), ipaddress.IPv6Network):
if kwargs.get('use_range', False):
network_obj = wapi.get_object('range', {'network': network})
elif isinstance(ipaddress.ip_network(network), ipaddress.IPv6Network):
network_obj = wapi.get_object('ipv6network', {'network': network})
else:
network_obj = wapi.get_object('network', {'network': network})
Expand Down

0 comments on commit 8b4f2d0

Please sign in to comment.