Added update_netbox_object to netbox_ip_address (#55070)
This commit is contained in:
parent
ee25c34d00
commit
0b5b353e37
1 changed files with 17 additions and 5 deletions
|
@ -228,6 +228,7 @@ from ansible.module_utils.net_tools.netbox.netbox_utils import (
|
||||||
normalize_data,
|
normalize_data,
|
||||||
create_netbox_object,
|
create_netbox_object,
|
||||||
delete_netbox_object,
|
delete_netbox_object,
|
||||||
|
update_netbox_object,
|
||||||
IP_ADDRESS_ROLE,
|
IP_ADDRESS_ROLE,
|
||||||
IP_ADDRESS_STATUS
|
IP_ADDRESS_STATUS
|
||||||
)
|
)
|
||||||
|
@ -352,16 +353,27 @@ def ensure_ip_address_present(nb_endpoint, data):
|
||||||
return {"msg": data, "changed": changed}
|
return {"msg": data, "changed": changed}
|
||||||
|
|
||||||
try:
|
try:
|
||||||
ip_addr = _search_ip(nb_endpoint, data)
|
nb_addr = _search_ip(nb_endpoint, data)
|
||||||
except ValueError:
|
except ValueError:
|
||||||
return _error_multiple_ip_results(data)
|
return _error_multiple_ip_results(data)
|
||||||
|
|
||||||
if not ip_addr:
|
result = {}
|
||||||
|
if not nb_addr:
|
||||||
return create_ip_address(nb_endpoint, data)
|
return create_ip_address(nb_endpoint, data)
|
||||||
else:
|
else:
|
||||||
ip_addr = ip_addr.serialize()
|
ip_addr, diff = update_netbox_object(nb_addr, data, module.check_mode)
|
||||||
changed = False
|
if ip_addr is False:
|
||||||
msg = "IP Address %s already exists" % (data["address"])
|
module.fail_json(
|
||||||
|
msg="Request failed, couldn't update IP: %s" % (data["address"])
|
||||||
|
)
|
||||||
|
if diff:
|
||||||
|
msg = "IP Address %s updated" % (data["address"])
|
||||||
|
changed = True
|
||||||
|
result["diff"] = diff
|
||||||
|
else:
|
||||||
|
ip_addr = nb_addr.serialize()
|
||||||
|
changed = False
|
||||||
|
msg = "IP Address %s already exists" % (data["address"])
|
||||||
|
|
||||||
return {"ip_address": ip_addr, "msg": msg, "changed": changed}
|
return {"ip_address": ip_addr, "msg": msg, "changed": changed}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue