From d07d3947794b10b35dab9a7b0fdcf31a4b0e1e56 Mon Sep 17 00:00:00 2001 From: Mikhail Yohman Date: Wed, 12 Jun 2019 08:45:20 -0600 Subject: [PATCH] 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 --- .../fragments/netbox_ip_address-fix-duplicate-ip.yaml | 6 ++++++ lib/ansible/module_utils/net_tools/netbox/netbox_utils.py | 5 +++-- 2 files changed, 9 insertions(+), 2 deletions(-) create mode 100644 changelogs/fragments/netbox_ip_address-fix-duplicate-ip.yaml diff --git a/changelogs/fragments/netbox_ip_address-fix-duplicate-ip.yaml b/changelogs/fragments/netbox_ip_address-fix-duplicate-ip.yaml new file mode 100644 index 00000000000..b94108ba84a --- /dev/null +++ b/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. diff --git a/lib/ansible/module_utils/net_tools/netbox/netbox_utils.py b/lib/ansible/module_utils/net_tools/netbox/netbox_utils.py index a6b92f68137..6c37eded415 100644 --- a/lib/ansible/module_utils/net_tools/netbox/netbox_utils.py +++ b/lib/ansible/module_utils/net_tools/netbox/netbox_utils.py @@ -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