Bugfix: Creating two IPs in single run of netbox_ip_address (#56550)

* Found bug, fixed by moving the serialization of objects out of try while creating objects

* Added changelog to document fix
This commit is contained in:
Mikhail Yohman 2019-06-12 08:45:20 -06:00 committed by Sloane Hertel
parent a50b3d7695
commit d07d394779
2 changed files with 9 additions and 2 deletions

View file

@ -0,0 +1,6 @@
---
bugfixes:
- >
netbox_ip_address - Fixed issue where it would create duplicate IP addresses when trying to serialize the IP address object
which doesn't have the ``.serialize()`` method. This should also prevent future duplicate objects being created if they don't
have the ``.serialize()`` method as well.

View file

@ -197,10 +197,11 @@ def create_netbox_object(nb_endpoint, data, check_mode):
if check_mode:
serialized_nb_obj = data
else:
nb_obj = nb_endpoint.create(data)
try:
serialized_nb_obj = nb_endpoint.create(data).serialize()
serialized_nb_obj = nb_obj.serialize()
except AttributeError:
serialized_nb_obj = nb_endpoint.create(data)
serialized_nb_obj = nb_obj
diff = _build_diff(before={"state": "absent"}, after={"state": "present"})
return serialized_nb_obj, diff