From 31b894278f5c880c71a555910e318f21d453f780 Mon Sep 17 00:00:00 2001 From: hramov-ms-230320 Date: Sat, 2 Nov 2024 15:11:28 +0300 Subject: [PATCH 1/9] Add missing elements to netbox_fhrp_group --- plugins/modules/netbox_fhrp_group.py | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) diff --git a/plugins/modules/netbox_fhrp_group.py b/plugins/modules/netbox_fhrp_group.py index 377dbada..45db4132 100644 --- a/plugins/modules/netbox_fhrp_group.py +++ b/plugins/modules/netbox_fhrp_group.py @@ -78,6 +78,22 @@ required: false type: list elements: raw + ip_address: + description: + - Virtual IP address for the FHRP group + type: str + required: false + ip_status: + description: + - IP address status + choices: + - dhcp + - reserved + - deprecated + - slaac + - active + type: str + required: false custom_fields: description: - Must exist in NetBox @@ -104,6 +120,8 @@ auth_type: md5 auth_key: 11111 description: test FHRP group + ip_address: 192.168.10.3/24 + ip_status: active state: present - name: Delete FHRP group within netbox @@ -165,6 +183,16 @@ def main(): auth_key=dict(type="str", no_log=True), description=dict(type="str"), tags=dict(required=False, type="list", elements="raw"), + ip_address=dict(required=False, type="str"), + ip_status=dict(type="str", + choices=[ + "dhcp", + "reserved", + "deprecated", + "slaac", + "active" + ] + ), custom_fields=dict(required=False, type="dict"), ), ), From 8fe17e362ae9dcbca9b92ecf9bcd3cfa8edd36ef Mon Sep 17 00:00:00 2001 From: hramov-ms-230320 Date: Wed, 6 Nov 2024 10:59:21 +0300 Subject: [PATCH 2/9] Add fhrpgroup option to netbox_ip_address --- plugins/modules/netbox_ip_address.py | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/plugins/modules/netbox_ip_address.py b/plugins/modules/netbox_ip_address.py index 961bab7b..6cc2cd3a 100644 --- a/plugins/modules/netbox_ip_address.py +++ b/plugins/modules/netbox_ip_address.py @@ -110,6 +110,11 @@ - Hostname or FQDN required: false type: str + fhrpgroup: + description: + - FHRP Group ID + required: false + type: str assigned_object: description: - Definition of the assigned object. @@ -333,6 +338,7 @@ def main(): description=dict(required=False, type="str"), nat_inside=dict(required=False, type="raw"), dns_name=dict(required=False, type="str"), + fhrpgroup=dict(required=False, type="str"), assigned_object=dict( required=False, type="dict", From 7c5f02e00190de3f1cc437e452975a5bbec22652 Mon Sep 17 00:00:00 2001 From: hramov-ms-230320 Date: Wed, 6 Nov 2024 11:34:49 +0300 Subject: [PATCH 3/9] add fragment --- changelogs/fragments/1349-add-additional-fhrp-arguments.yaml | 3 +++ 1 file changed, 3 insertions(+) create mode 100644 changelogs/fragments/1349-add-additional-fhrp-arguments.yaml diff --git a/changelogs/fragments/1349-add-additional-fhrp-arguments.yaml b/changelogs/fragments/1349-add-additional-fhrp-arguments.yaml new file mode 100644 index 00000000..e4f45fa6 --- /dev/null +++ b/changelogs/fragments/1349-add-additional-fhrp-arguments.yaml @@ -0,0 +1,3 @@ +minor_changes: + - in netbox_fhrp_group added ip_address and ip_status options + - in netbox_ip_address added fhrpgroup options \ No newline at end of file From a998b716361a2372307820c96930e3ae02e93bfc Mon Sep 17 00:00:00 2001 From: hramov-ms-230320 Date: Wed, 6 Nov 2024 11:35:24 +0300 Subject: [PATCH 4/9] add whitespace in fragment --- changelogs/fragments/1349-add-additional-fhrp-arguments.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/changelogs/fragments/1349-add-additional-fhrp-arguments.yaml b/changelogs/fragments/1349-add-additional-fhrp-arguments.yaml index e4f45fa6..95e9822f 100644 --- a/changelogs/fragments/1349-add-additional-fhrp-arguments.yaml +++ b/changelogs/fragments/1349-add-additional-fhrp-arguments.yaml @@ -1,3 +1,3 @@ minor_changes: - in netbox_fhrp_group added ip_address and ip_status options - - in netbox_ip_address added fhrpgroup options \ No newline at end of file + - in netbox_ip_address added fhrpgroup options From c192cac6525cd618ffaacb21254b4fbcc57cf6b0 Mon Sep 17 00:00:00 2001 From: hramov-ms-230320 Date: Wed, 6 Nov 2024 11:52:24 +0300 Subject: [PATCH 5/9] Add examples --- plugins/modules/netbox_ip_address.py | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/plugins/modules/netbox_ip_address.py b/plugins/modules/netbox_ip_address.py index 6cc2cd3a..e06ebac7 100644 --- a/plugins/modules/netbox_ip_address.py +++ b/plugins/modules/netbox_ip_address.py @@ -269,6 +269,15 @@ name: GigabitEthernet1 device: test100 state: new + + - name: Create an IP address using NetBox and add it to the FHRP group + netbox.netbox.netbox_ip_address: + netbox_url: http://netbox.local + netbox_token: thisIsMyToken + data: + address: 192.168.1.10 + fhrpgroup: 10 + state: present """ RETURN = r""" From e58acf10059314e1438bc12b8b6bd04cbd6d9513 Mon Sep 17 00:00:00 2001 From: hramov-ms-230320 Date: Wed, 6 Nov 2024 11:58:56 +0300 Subject: [PATCH 6/9] fix whitespace --- plugins/modules/netbox_ip_address.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/plugins/modules/netbox_ip_address.py b/plugins/modules/netbox_ip_address.py index e06ebac7..add0ac40 100644 --- a/plugins/modules/netbox_ip_address.py +++ b/plugins/modules/netbox_ip_address.py @@ -269,7 +269,7 @@ name: GigabitEthernet1 device: test100 state: new - + - name: Create an IP address using NetBox and add it to the FHRP group netbox.netbox.netbox_ip_address: netbox_url: http://netbox.local From 34188b8ae809d3eedaff359be01f44771f5f4652 Mon Sep 17 00:00:00 2001 From: hramov-ms-230320 Date: Wed, 6 Nov 2024 11:59:22 +0300 Subject: [PATCH 7/9] fix whitespace --- plugins/modules/netbox_ip_address.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/plugins/modules/netbox_ip_address.py b/plugins/modules/netbox_ip_address.py index add0ac40..3c811d00 100644 --- a/plugins/modules/netbox_ip_address.py +++ b/plugins/modules/netbox_ip_address.py @@ -269,7 +269,7 @@ name: GigabitEthernet1 device: test100 state: new - + - name: Create an IP address using NetBox and add it to the FHRP group netbox.netbox.netbox_ip_address: netbox_url: http://netbox.local From a8c3bc55ab4f6b873f1c21f2aa67b907261b7194 Mon Sep 17 00:00:00 2001 From: hramov-ms-230320 Date: Thu, 7 Nov 2024 10:18:31 +0300 Subject: [PATCH 8/9] fix options in netbox_fhrp_group.py and netbox_ip_address.py --- .../1349-add-additional-fhrp-arguments.yaml | 3 +- plugins/modules/netbox_fhrp_group.py | 28 ------------------- plugins/modules/netbox_ip_address.py | 17 +++++++---- 3 files changed, 13 insertions(+), 35 deletions(-) diff --git a/changelogs/fragments/1349-add-additional-fhrp-arguments.yaml b/changelogs/fragments/1349-add-additional-fhrp-arguments.yaml index 95e9822f..58363075 100644 --- a/changelogs/fragments/1349-add-additional-fhrp-arguments.yaml +++ b/changelogs/fragments/1349-add-additional-fhrp-arguments.yaml @@ -1,3 +1,2 @@ minor_changes: - - in netbox_fhrp_group added ip_address and ip_status options - - in netbox_ip_address added fhrpgroup options + - in netbox_ip_address added assigned_object_type and assigned_object_id options diff --git a/plugins/modules/netbox_fhrp_group.py b/plugins/modules/netbox_fhrp_group.py index 45db4132..377dbada 100644 --- a/plugins/modules/netbox_fhrp_group.py +++ b/plugins/modules/netbox_fhrp_group.py @@ -78,22 +78,6 @@ required: false type: list elements: raw - ip_address: - description: - - Virtual IP address for the FHRP group - type: str - required: false - ip_status: - description: - - IP address status - choices: - - dhcp - - reserved - - deprecated - - slaac - - active - type: str - required: false custom_fields: description: - Must exist in NetBox @@ -120,8 +104,6 @@ auth_type: md5 auth_key: 11111 description: test FHRP group - ip_address: 192.168.10.3/24 - ip_status: active state: present - name: Delete FHRP group within netbox @@ -183,16 +165,6 @@ def main(): auth_key=dict(type="str", no_log=True), description=dict(type="str"), tags=dict(required=False, type="list", elements="raw"), - ip_address=dict(required=False, type="str"), - ip_status=dict(type="str", - choices=[ - "dhcp", - "reserved", - "deprecated", - "slaac", - "active" - ] - ), custom_fields=dict(required=False, type="dict"), ), ), diff --git a/plugins/modules/netbox_ip_address.py b/plugins/modules/netbox_ip_address.py index 3c811d00..412f0f34 100644 --- a/plugins/modules/netbox_ip_address.py +++ b/plugins/modules/netbox_ip_address.py @@ -110,11 +110,16 @@ - Hostname or FQDN required: false type: str - fhrpgroup: + assigned_object_id: description: - - FHRP Group ID + - ID of the assigned object + type: str + required: false + assigned_object_type: + description: + - Type of the assigned object + type: str required: false - type: str assigned_object: description: - Definition of the assigned object. @@ -276,7 +281,8 @@ netbox_token: thisIsMyToken data: address: 192.168.1.10 - fhrpgroup: 10 + assigned_object_id: 30 + assigned_object_type: "ipam.fhrpgroup" state: present """ @@ -347,7 +353,8 @@ def main(): description=dict(required=False, type="str"), nat_inside=dict(required=False, type="raw"), dns_name=dict(required=False, type="str"), - fhrpgroup=dict(required=False, type="str"), + assigned_object_id=dict(required=False, type="str"), + assigned_object_type=dict(required=False, type="str"), assigned_object=dict( required=False, type="dict", From 6328de26c58d5f8344e690a3c0446dac86ca05f3 Mon Sep 17 00:00:00 2001 From: hramov-ms-230320 Date: Thu, 7 Nov 2024 15:07:28 +0300 Subject: [PATCH 9/9] In the netbox_fhrp_group, the name parameter is now required, which is used to search --- changelogs/fragments/1349-add-additional-fhrp-arguments.yaml | 1 + plugins/module_utils/netbox_ipam.py | 2 +- plugins/module_utils/netbox_utils.py | 4 ++-- plugins/modules/netbox_fhrp_group.py | 2 +- 4 files changed, 5 insertions(+), 4 deletions(-) diff --git a/changelogs/fragments/1349-add-additional-fhrp-arguments.yaml b/changelogs/fragments/1349-add-additional-fhrp-arguments.yaml index 58363075..3c078dab 100644 --- a/changelogs/fragments/1349-add-additional-fhrp-arguments.yaml +++ b/changelogs/fragments/1349-add-additional-fhrp-arguments.yaml @@ -1,2 +1,3 @@ minor_changes: - in netbox_ip_address added assigned_object_type and assigned_object_id options + - In the netbox_fhrp_group, the `name` parameter is now required, which is used to search. diff --git a/plugins/module_utils/netbox_ipam.py b/plugins/module_utils/netbox_ipam.py index 8d1b731f..8fa41258 100644 --- a/plugins/module_utils/netbox_ipam.py +++ b/plugins/module_utils/netbox_ipam.py @@ -189,7 +189,7 @@ def run(self): elif self.endpoint == "asns": name = data.get("asn") elif self.endpoint == "fhrp_groups": - name = data.get("group_id") + name = data.get("name") elif self.endpoint == "fhrp_group_assignments": name = "fhrp_group %s > %s %s" % ( data.get("group"), diff --git a/plugins/module_utils/netbox_utils.py b/plugins/module_utils/netbox_utils.py index ea76f43c..52eb975c 100644 --- a/plugins/module_utils/netbox_utils.py +++ b/plugins/module_utils/netbox_utils.py @@ -164,7 +164,7 @@ device_type="slug", export_targets="name", export_template="name", - fhrp_groups="group_id", + fhrp_groups="name", fhrp_group_assignments="id", group="slug", groups="name", @@ -493,7 +493,7 @@ "device_type": set(["slug"]), "export_template": set(["name"]), "fhrp_group": set( - ["id", "group_id", "interface_type", "device", "virtual_machine"] + ["id", "group_id","name", "interface_type", "device", "virtual_machine"] ), "fhrp_group_assignment": set(["group", "interface_type", "interface_id"]), "front_port": set(["name", "device", "rear_port"]), diff --git a/plugins/modules/netbox_fhrp_group.py b/plugins/modules/netbox_fhrp_group.py index 377dbada..f655a031 100644 --- a/plugins/modules/netbox_fhrp_group.py +++ b/plugins/modules/netbox_fhrp_group.py @@ -147,7 +147,7 @@ def main(): type="dict", required=True, options=dict( - name=dict(type="str"), + name=dict(type="str", required=True), protocol=dict( type="str", choices=[