Skip to content

Commit

Permalink
Bugfix: Creating two IPs in single run of netbox_ip_address (#56550)
Browse files Browse the repository at this point in the history
* Found bug, fixed by moving the serialization of objects out of try while creating objects

* Added changelog to document fix
  • Loading branch information
FragmentedPacket authored and s-hertel committed Jun 12, 2019
1 parent a50b3d7 commit d07d394
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 2 deletions.
6 changes: 6 additions & 0 deletions changelogs/fragments/netbox_ip_address-fix-duplicate-ip.yaml
@@ -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.
5 changes: 3 additions & 2 deletions lib/ansible/module_utils/net_tools/netbox/netbox_utils.py
Expand Up @@ -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
Expand Down

0 comments on commit d07d394

Please sign in to comment.