From 0753b87aa0b62fa3c305b4fb2ae4417c24888d02 Mon Sep 17 00:00:00 2001 From: Matej Stajduhar Date: Fri, 10 Apr 2026 11:25:23 +0200 Subject: [PATCH 1/8] New ansible module to list private NICs --- plugins/modules/scaleway_private_nic_info.py | 168 +++++++++++++++++++ 1 file changed, 168 insertions(+) create mode 100644 plugins/modules/scaleway_private_nic_info.py diff --git a/plugins/modules/scaleway_private_nic_info.py b/plugins/modules/scaleway_private_nic_info.py new file mode 100644 index 0000000000..86ddfdf303 --- /dev/null +++ b/plugins/modules/scaleway_private_nic_info.py @@ -0,0 +1,168 @@ +#!/usr/bin/python +# +# Copyright (c) 2018, Yanis Guenane +# GNU General Public License v3.0+ (see LICENSES/GPL-3.0-or-later.txt or https://www.gnu.org/licenses/gpl-3.0.txt) +# SPDX-License-Identifier: GPL-3.0-or-later + +from __future__ import annotations + +DOCUMENTATION = r""" +module: scaleway_ip_info +short_description: Lists private NICs of the instance +description: + - Lists all private networks that are associated with the provided instance. +author: + - "Yanis Guenane (@Spredzy)" + - "Remy Leone (@remyleone)" +extends_documentation_fragment: + - community.general.scaleway + - community.general.attributes + - community.general.scaleway.actiongroup_scaleway + - community.general.attributes.info_module + +attributes: + action_group: + version_added: 11.3.0 + +options: + region: + type: str + description: + - Scaleway region to use (for example C(par1)). + required: true + choices: + - ams1 + - EMEA-NL-EVS + - ams2 + - ams3 + - par1 + - EMEA-FR-PAR1 + - par2 + - EMEA-FR-PAR2 + - par3 + - waw1 + - EMEA-PL-WAW1 + - waw2 + - waw3 + instance_id: + type: str + description: + - ID of the insance. + required: true +""" + +EXAMPLES = r""" +- name: Get private network information and register it in a variable + community.general.scaleway_private_nic_info: + region: par1 + instance_id: "1234ab-ab12-12ab-12a3-12345678ab9c" + register: nics + +- name: Display nics variable + debug: + var: nics +""" + +RETURN = r""" +private_nics: + description: + - Response from Scaleway API. + - For more details please refer to U(https://developers.scaleway.com/en/products/instance/api/). + returned: always + type: list + elements: dict + contains: + "creation_date": + description: Private NIC creation date. + sample: "2026-04-09T00:00:00.000000+00:00" + type: string + "id": + description: Private NIC unique ID. + sample: "abc123ab-12ab-12ab-12ab-123abc123abc" + type: string + "ipam_ip_ids": + description: UUID of IPAM ips. + sample: + [ + "1234abcd-34cd-12ab-56ab-123abc123abc", + "5678abcd-12ab-34cd-ab56-123abc123abc" + ] + type: list + elements: string + "mac_address": + description: Private NIC MAC address. + sample: "12:34:ab:cd:1a:2b" + type: string + "modification_date": + description: Private NIC last modified date. + sample: "2026-04-09T00:00:01.000000+00:00" + type: string + "private_network_id": + description: ID of the private Network the private NIC is attached to. + sample: "1234abcd-12ab-12ab-12ab-123abc123abc" + type: string + "server_id": + description: ID of the server which is used for request. + sample: "1234ab-ab12-12ab-12a3-12345678ab9c" + type: string + "state": + description: Private NIC state. + sample: "available" + type: string + "tags": + description: Tags associated with Private NIC. + sample: + [ + "main", + "test" + ] + type: list + elements: string + "zone": + description: The zone in which the Private NIC is located. + sample: "fr-par-1" + type: string +""" + +from ansible.module_utils.basic import AnsibleModule + +from ansible_collections.community.general.plugins.module_utils.scaleway import ( + SCALEWAY_LOCATION, + Scaleway, + ScalewayException, + scaleway_argument_spec, +) + +def list_strategy(api): + private_nics = api.get(path=api.api_path) + + return private_nics.json + +def core(module): + region = module.params["region"] + instance_id = module.params["instance_id"] + + module.params["api_url"] = SCALEWAY_LOCATION[region]["api_endpoint"] + api = Scaleway(module=module) + api.api_path = f"servers/{instance_id}/private_nics" + + try: + list = list_strategy(api=api) + module.exit_json(private_nics=list["private_nics"]) + except ScalewayException as exc: + module.fail_json(msg=exc.message) + +def main(): + argument_spec = scaleway_argument_spec() + argument_spec.update( + dict(region=dict(required=True, choices=list(SCALEWAY_LOCATION.keys())), instance_id=dict(required=True)) + ) + module = AnsibleModule( + argument_spec=argument_spec, + supports_check_mode=True, + ) + + core(module) + +if __name__ == "__main__": + main() From 62966964678be697172762ee7e98ce2955bd54fb Mon Sep 17 00:00:00 2001 From: Matej Stajduhar Date: Fri, 10 Apr 2026 16:11:09 +0200 Subject: [PATCH 2/8] Fixing-linting --- plugins/modules/scaleway_private_nic_info.py | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/plugins/modules/scaleway_private_nic_info.py b/plugins/modules/scaleway_private_nic_info.py index 86ddfdf303..cf64e4057d 100644 --- a/plugins/modules/scaleway_private_nic_info.py +++ b/plugins/modules/scaleway_private_nic_info.py @@ -7,10 +7,10 @@ from __future__ import annotations DOCUMENTATION = r""" -module: scaleway_ip_info -short_description: Lists private NICs of the instance +module: scaleway_private_nic_info +short_description: List all private NICs description: - - Lists all private networks that are associated with the provided instance. + - List all private NICs of a specified Instance. author: - "Yanis Guenane (@Spredzy)" - "Remy Leone (@remyleone)" @@ -52,13 +52,13 @@ options: """ EXAMPLES = r""" -- name: Get private network information and register it in a variable +- name: Get information about all private NICs of specified instance and register it in a variable community.general.scaleway_private_nic_info: region: par1 instance_id: "1234ab-ab12-12ab-12a3-12345678ab9c" register: nics -- name: Display nics variable +- name: Display nics debug: var: nics """ @@ -133,11 +133,13 @@ from ansible_collections.community.general.plugins.module_utils.scaleway import scaleway_argument_spec, ) + def list_strategy(api): private_nics = api.get(path=api.api_path) return private_nics.json + def core(module): region = module.params["region"] instance_id = module.params["instance_id"] @@ -152,6 +154,7 @@ def core(module): except ScalewayException as exc: module.fail_json(msg=exc.message) + def main(): argument_spec = scaleway_argument_spec() argument_spec.update( @@ -164,5 +167,6 @@ def main(): core(module) + if __name__ == "__main__": main() From 012d606f679ce00ed406525d620802ee4e4cb5bf Mon Sep 17 00:00:00 2001 From: Matej Stajduhar Date: Fri, 10 Apr 2026 16:25:36 +0200 Subject: [PATCH 3/8] Changing type and elements to str instead of string --- plugins/modules/scaleway_private_nic_info.py | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/plugins/modules/scaleway_private_nic_info.py b/plugins/modules/scaleway_private_nic_info.py index cf64e4057d..39f05126ed 100644 --- a/plugins/modules/scaleway_private_nic_info.py +++ b/plugins/modules/scaleway_private_nic_info.py @@ -75,11 +75,11 @@ private_nics: "creation_date": description: Private NIC creation date. sample: "2026-04-09T00:00:00.000000+00:00" - type: string + type: str "id": description: Private NIC unique ID. sample: "abc123ab-12ab-12ab-12ab-123abc123abc" - type: string + type: str "ipam_ip_ids": description: UUID of IPAM ips. sample: @@ -88,27 +88,27 @@ private_nics: "5678abcd-12ab-34cd-ab56-123abc123abc" ] type: list - elements: string + elements: str "mac_address": description: Private NIC MAC address. sample: "12:34:ab:cd:1a:2b" - type: string + type: str "modification_date": description: Private NIC last modified date. sample: "2026-04-09T00:00:01.000000+00:00" - type: string + type: str "private_network_id": description: ID of the private Network the private NIC is attached to. sample: "1234abcd-12ab-12ab-12ab-123abc123abc" - type: string + type: str "server_id": description: ID of the server which is used for request. sample: "1234ab-ab12-12ab-12a3-12345678ab9c" - type: string + type: str "state": description: Private NIC state. sample: "available" - type: string + type: str "tags": description: Tags associated with Private NIC. sample: @@ -117,11 +117,11 @@ private_nics: "test" ] type: list - elements: string + elements: str "zone": description: The zone in which the Private NIC is located. sample: "fr-par-1" - type: string + type: str """ from ansible.module_utils.basic import AnsibleModule From af29b4fa062ac75562ec5ac8b08eea47e87e60c9 Mon Sep 17 00:00:00 2001 From: Matej Stajduhar Date: Thu, 28 May 2026 07:46:17 +0200 Subject: [PATCH 4/8] Updated-the-module-as-discussed --- plugins/modules/scaleway_private_nic_info.py | 25 ++++++++------------ 1 file changed, 10 insertions(+), 15 deletions(-) diff --git a/plugins/modules/scaleway_private_nic_info.py b/plugins/modules/scaleway_private_nic_info.py index 39f05126ed..3cbdb70f00 100644 --- a/plugins/modules/scaleway_private_nic_info.py +++ b/plugins/modules/scaleway_private_nic_info.py @@ -1,29 +1,24 @@ #!/usr/bin/python -# -# Copyright (c) 2018, Yanis Guenane -# GNU General Public License v3.0+ (see LICENSES/GPL-3.0-or-later.txt or https://www.gnu.org/licenses/gpl-3.0.txt) -# SPDX-License-Identifier: GPL-3.0-or-later +# -*- coding: utf-8 -*- + +# Copyright: Contributors to the Ansible project +# GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt) from __future__ import annotations DOCUMENTATION = r""" -module: scaleway_private_nic_info -short_description: List all private NICs +module: scaleway_ip_info +short_description: Lists private NICs of the instance. description: - - List all private NICs of a specified Instance. -author: - - "Yanis Guenane (@Spredzy)" - - "Remy Leone (@remyleone)" + - Lists all private networks that are associated with the provided instance. +version_added: "12.5" +author: "Matej Stajduhar (@matej5)" extends_documentation_fragment: - community.general.scaleway - community.general.attributes - community.general.scaleway.actiongroup_scaleway - community.general.attributes.info_module -attributes: - action_group: - version_added: 11.3.0 - options: region: type: str @@ -150,7 +145,7 @@ def core(module): try: list = list_strategy(api=api) - module.exit_json(private_nics=list["private_nics"]) + module.exit_json(private_nics=list) except ScalewayException as exc: module.fail_json(msg=exc.message) From 1ab1d2049da2f924396d09bd92f72444c3ff7c0a Mon Sep 17 00:00:00 2001 From: Matej Stajduhar Date: Thu, 28 May 2026 07:58:44 +0200 Subject: [PATCH 5/8] Fixed-module-name-in-documentation --- plugins/modules/scaleway_private_nic_info.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/plugins/modules/scaleway_private_nic_info.py b/plugins/modules/scaleway_private_nic_info.py index 3cbdb70f00..cedba9f509 100644 --- a/plugins/modules/scaleway_private_nic_info.py +++ b/plugins/modules/scaleway_private_nic_info.py @@ -7,7 +7,7 @@ from __future__ import annotations DOCUMENTATION = r""" -module: scaleway_ip_info +module: scaleway_private_nic_info short_description: Lists private NICs of the instance. description: - Lists all private networks that are associated with the provided instance. From e4642895dc09a4a6e8fe44ebef413764b8458b5f Mon Sep 17 00:00:00 2001 From: Matej Stajduhar Date: Thu, 28 May 2026 10:20:53 +0200 Subject: [PATCH 6/8] Fixed-version_added --- plugins/modules/scaleway_private_nic_info.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/plugins/modules/scaleway_private_nic_info.py b/plugins/modules/scaleway_private_nic_info.py index cedba9f509..ad3718e135 100644 --- a/plugins/modules/scaleway_private_nic_info.py +++ b/plugins/modules/scaleway_private_nic_info.py @@ -11,7 +11,7 @@ module: scaleway_private_nic_info short_description: Lists private NICs of the instance. description: - Lists all private networks that are associated with the provided instance. -version_added: "12.5" +version_added: "12.5.0" author: "Matej Stajduhar (@matej5)" extends_documentation_fragment: - community.general.scaleway From f168d6866a0031e65f153feebc6cb0716e05bc3e Mon Sep 17 00:00:00 2001 From: Matej Stajduhar Date: Thu, 28 May 2026 10:24:54 +0200 Subject: [PATCH 7/8] utf-8-comment-causing errors when running nox --- plugins/modules/scaleway_private_nic_info.py | 1 - 1 file changed, 1 deletion(-) diff --git a/plugins/modules/scaleway_private_nic_info.py b/plugins/modules/scaleway_private_nic_info.py index ad3718e135..205fc032fd 100644 --- a/plugins/modules/scaleway_private_nic_info.py +++ b/plugins/modules/scaleway_private_nic_info.py @@ -1,5 +1,4 @@ #!/usr/bin/python -# -*- coding: utf-8 -*- # Copyright: Contributors to the Ansible project # GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt) From b035bbe0121df4af3596a99f1833c25d3ab480c1 Mon Sep 17 00:00:00 2001 From: Matej Stajduhar Date: Mon, 1 Jun 2026 18:07:32 +0200 Subject: [PATCH 8/8] Updating-scaleway-name-for-import --- plugins/modules/scaleway_private_nic_info.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/plugins/modules/scaleway_private_nic_info.py b/plugins/modules/scaleway_private_nic_info.py index 205fc032fd..4b8277142f 100644 --- a/plugins/modules/scaleway_private_nic_info.py +++ b/plugins/modules/scaleway_private_nic_info.py @@ -120,7 +120,7 @@ private_nics: from ansible.module_utils.basic import AnsibleModule -from ansible_collections.community.general.plugins.module_utils.scaleway import ( +from ansible_collections.community.general.plugins.module_utils._scaleway import ( SCALEWAY_LOCATION, Scaleway, ScalewayException,