mirror of
https://github.com/ansible-collections/community.general.git
synced 2025-04-28 21:31:26 -07:00
Added Support for excluding IPs in nios_next_ip and created new pluggin for nios_next_network (#44437)
* adding next network pluggin * include exclude option for next_ip search * changing example provider input * adding new line at end * version added info * to fix shippable errors * to fix shippable errors * adding exclude option in doc section * fix review comment * fix review comment
This commit is contained in:
parent
1d2bb34992
commit
b1f915b28b
2 changed files with 122 additions and 1 deletions
|
@ -39,6 +39,10 @@ options:
|
|||
description: The number of IP addresses to return
|
||||
required: false
|
||||
default: 1
|
||||
exclude:
|
||||
version_added: "2.7"
|
||||
description: List of IP's that need to be excluded from returned IP addresses
|
||||
required: false
|
||||
"""
|
||||
|
||||
EXAMPLES = """
|
||||
|
@ -49,6 +53,11 @@ EXAMPLES = """
|
|||
- name: return the next 3 available IP addresses for network 192.168.10.0/24
|
||||
set_fact:
|
||||
ipaddr: "{{ lookup('nios_next_ip', '192.168.10.0/24', num=3, provider={'host': 'nios01', 'username': 'admin', 'password': 'password'}) }}"
|
||||
|
||||
- name: return the next 3 available IP addresses for network 192.168.10.0/24 excluding ip addresses - ['192.168.10.1', '192.168.10.2']
|
||||
set_fact:
|
||||
ipaddr: "{{ lookup('nios_next_ip', '192.168.10.0/24', num=3, exclude=['192.168.10.1', '192.168.10.2'],
|
||||
provider={'host': 'nios01', 'username': 'admin', 'password': 'password'}) }}"
|
||||
"""
|
||||
|
||||
RETURN = """
|
||||
|
@ -81,10 +90,11 @@ class LookupModule(LookupBase):
|
|||
raise AnsibleError('unable to find network object %s' % network)
|
||||
|
||||
num = kwargs.get('num', 1)
|
||||
exclude_ip = kwargs.get('exclude', [])
|
||||
|
||||
try:
|
||||
ref = network_obj[0]['_ref']
|
||||
avail_ips = wapi.call_func('next_available_ip', ref, {'num': num})
|
||||
avail_ips = wapi.call_func('next_available_ip', ref, {'num': num, 'exclude': exclude_ip})
|
||||
return [avail_ips['ips']]
|
||||
except Exception as exc:
|
||||
raise AnsibleError(to_text(exc))
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue