From 7cd7a428a804b511c3e53e5054f6bc8a8a3b343c Mon Sep 17 00:00:00 2001 From: Fred-sun Date: Wed, 10 Jan 2024 21:49:35 +0800 Subject: [PATCH 1/9] Add azure_rm_publicipprefix relate modules --- plugins/modules/azure_rm_publicipprefix.py | 432 ++++++++++++++++++ .../modules/azure_rm_publicipprefix_info.py | 276 +++++++++++ pr-pipelines.yml | 1 + .../targets/azure_rm_publicipprefix/aliases | 3 + .../azure_rm_publicipprefix/meta/main.yml | 2 + .../azure_rm_publicipprefix/tasks/main.yml | 102 +++++ 6 files changed, 816 insertions(+) create mode 100644 plugins/modules/azure_rm_publicipprefix.py create mode 100644 plugins/modules/azure_rm_publicipprefix_info.py create mode 100644 tests/integration/targets/azure_rm_publicipprefix/aliases create mode 100644 tests/integration/targets/azure_rm_publicipprefix/meta/main.yml create mode 100644 tests/integration/targets/azure_rm_publicipprefix/tasks/main.yml diff --git a/plugins/modules/azure_rm_publicipprefix.py b/plugins/modules/azure_rm_publicipprefix.py new file mode 100644 index 000000000..9637cc037 --- /dev/null +++ b/plugins/modules/azure_rm_publicipprefix.py @@ -0,0 +1,432 @@ +#!/usr/bin/python +# +# Copyright (c) 2024 xuzhang3 (@xuzhang3), Fred-Sun (@Fred-Sun) +# +# GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt) + +from __future__ import absolute_import, division, print_function +__metaclass__ = type + + +DOCUMENTATION = ''' +--- +module: azure_rm_publicipprefix + +version_added: "2.2.0" + +short_description: Manage Azure Public IP prefix + +description: + - Create, update and delete a Public IP prefix. + +options: + resource_group: + description: + - Name of resource group with which the Public IP prefix is associated. + required: true + type: str + name: + description: + - Name of the Public IP prefix. + required: true + type: str + state: + description: + - Assert the state of the Public IP. Use C(present) to create or update a and C(absent) to delete. + default: present + type: str + choices: + - absent + - present + location: + description: + - Valid Azure location. Defaults to location of the resource group. + type: str + sku: + description: + - The public IP prefix SKU. + type: dict + suboptions: + name: + descritpion: + - Name of a public IP prefix SKU. + type: str + choices: + - Standard + tier: + description: + - Tier of a public IP prefix SKU. + type: str + choices: + - Regional + - Global + custom_ip_prefix: + description: + - The customIpPrefix that this prefix is associated with. + type: dict + suboptions: + id: + descritption: + - + type: str + extended_location: + description: + - The extended location of the public ip address. + type: str + ip_tags: + description: + - The list of tags associated with the public IP prefix. + type: list + elements: dict + suboptions: + ip_tag_type: + description: + - The IP tag type. Example: FirstPartyUsage. + type: str + tag: + description: + - The value of the IP tag associated with the public IP. Example: SQL. + type: str + public_ip_address_version: + description: + - The public IP address version. + choices: + - IPV4 + - IPV6 + default: ipv4 + zones: + description: + - A list of availability zones denoting the IP prefix allocated for the resource needs to come from. + type: list + elements: str + choices: + - '1' + - '2' + - '3' + prefix_lenth: + description: + - The Length of the Public IP Prefix. + type: int + +extends_documentation_fragment: + - azure.azcollection.azure + - azure.azcollection.azure_tags + +author: + - xuzhang3 (@xuzhang3) + - Fred-sun (@Fred-sun) +''' + +EXAMPLES = ''' + - name: Create a public ip prefix + azure_rm_publicipprefix: + resource_group: myResourceGroup + name: my_public_ip + public_ip_address_version: IPV4 + prefix_length: 29 + sku: + name: Standard + tier: Regional + zones: + - 1 + tags: + key1: value1 + + - name: Delete public ip prefix + azure_rm_publicipprefix: + resource_group: myResourceGroup + name: my_public_ipprefix + state: absent +''' + +RETURN = ''' +state: + description: + - List of public IP prefixes dicts. + returned: always + type: complex + contains: + id: + description: + - Resource ID. + returned: always + type: str + sample: /subscriptions/xxx---xxxxx/resourceGroups/v-xisuRG/providers/Microsoft.Network/publicIPPrefixes/pipb57dc95224 + name: + description: + - Name of the public IP prefix. + returned: always + type: str + sample: prefix57dc95224 + type: + description: + - Resource type. + returned: always + type: str + sample: "Microsoft.Network/publicIPPrefixes" + location: + description: + - Resource location. + returned: always + type: str + sample: eastus + tags: + description: + - Resource tags. + returned: always + type: dict + sample: { + "delete": "on-exit", + "testing": "testing" + } + public_ip_address_version: + description: + - The public IP address version. + - Possible values are C(IPv4) and C(IPv6). + returned: always + type: str + sample: IPv4 + ip_tags: + description: + - The list of tags associated with the public IP prefixes. + returned: always +''' + +from ansible_collections.azure.azcollection.plugins.module_utils.azure_rm_common import AzureRMModuleBase + +try: + from azure.core.exceptions import ResourceNotFoundError +except ImportError: + # This is handled in azure_rm_common + pass + + +def prefix_to_dict(prefix): + result = dict( + id=prefix.id, + name=prefix.name, + tags=prefix.tags, + type=prefix.type, + location=prefix.location, + public_ip_address_version=prefix.public_ip_address_version, + prefix_length=prefix.prefix_length, + provisioning_state=prefix.provisioning_state, + etag=prefix.etag, + zones=prefix.zones, + sku=dict(), + ip_tags=dict(), + custom_ip_prefix=dict(), + extended_location=prefix.extended_location + ) + if prefix.sku: + result['sku']['name'] = prefix.sku.name + result['sku']['tier'] = prefix.sku.tier + if prefix.custom_ip_prefix: + result['custom_ip_prefix']['id'] = prefix.custom_ip_prefix.id + if prefix.ip_tags: + result['ip_tags'] = [dict(type=x.ip_tag_type, value=x.tag) for x in prefix.ip_tags] + return result + + +class AzureRMPublicIPPrefix(AzureRMModuleBase): + + def __init__(self): + + self.module_arg_spec = dict( + resource_group=dict(type='str', required=True), + name=dict(type='str', required=True), + state=dict(type='str', default='present', choices=['present', 'absent']), + location=dict(type='str'), + public_ip_address_version=dict(type='str', choices=['IPV4', 'IPV6']), + extended_location=dict(type='str'), + prefix_length=dict(type='int'), + custom_ip_prefix=dict( + type='dict', + options=dict( + id=dict(type='str') + ) + ), + sku=dict( + type='dict', + options=dict( + name=dict(type='str', choices=['Standard']), + tier=dict(type='str', choices=['Regional', 'Global']) + ) + ), + ip_tags=dict( + type='list', + elements='dict', + options=dict( + ip_tag_type=dict(type='str'), + tag=dict(type='str') + ) + ), + zones=dict(type='list', elements='str', choices=['1', '2', '3']) + ) + + self.resource_group = None + self.name = None + self.location = None + self.state = None + self.tags = None + self.zones = None + self.sku = None + self.ip_tags = None + self.public_ip_address_version = None + self.prefix_length = None + self.custom_ip_prefix = None + + self.results = dict( + changed=False, + state=dict() + ) + + super(AzureRMPublicIPPrefix, self).__init__(derived_arg_spec=self.module_arg_spec, + supports_check_mode=True) + + def exec_module(self, **kwargs): + + for key in list(self.module_arg_spec.keys()) + ['tags']: + setattr(self, key, kwargs[key]) + + results = dict() + changed = False + prefix = None + update_tags = False + + resource_group = self.get_resource_group(self.resource_group) + if not self.location: + # Set default location + self.location = resource_group.location + + try: + self.log("Fetch public ip prefix {0}".format(self.name)) + prefix = self.network_client.public_ip_prefixes.get(self.resource_group, self.name) + self.log("Public IP prefix {0} exists".format(self.name)) + + if self.state == 'present': + results = prefix_to_dict(prefix) + + if self.public_ip_address_version is not None and \ + self.public_ip_address_version.lower() != results['public_ip_address_version'].lower(): + changed = False + results['public_ip_address_version'] = self.public_ip_address_version + self.fail("The public_ip_address_version can't be updated") + + if self.prefix_length is not None and self.prefix_length != results['prefix_length']: + changed = False + results['prefix_length'] = self.prefix_length + self.fail("The prefix_length can't be updated") + + if self.sku is not None: + for key in self.sku.keys(): + if self.sku[key] != results['sku'].get(key): + changed = False + self.fail("The sku can't be updated") + results['sku'] = self.sku + + if self.zones is not None and not all(key in results['zones'] for key in self.zones): + changed = False + results['zones'] = self.zones + self.fail("The zone can't be updated") + + if self.extended_location is not None and self.extended_location != results['extended_location']: + changed = False + results['extended_location'] = self.extended_location + self.fail("The extended_location can't be updated") + + if self.ip_tags is not None: + for key in self.ip_tags.keys(): + if self.ip_tags[key] != results['ip_tags'].get(key): + changed = False + results['ip_tags'] = self.ip_tags + self.fail("The ip_tags can't be updated") + + if self.custom_ip_prefix is not None: + if results.get('custom_ip_prefix') is None: + changed = False + results['custom_ip_prefix'] = self.custom_ip_prefix + self.fail("The custom_ip_prefix can't be updated") + elif self.custom_ip_prefix['id'].lower() != results['custom_ip_prefix']['id'].lower(): + changed = False + results['custom_ip_prefix'] = self.custom_ip_prefix + self.fail("The custom_ip_prefix can't be updated") + + update_tags, results['tags'] = self.update_tags(results['tags']) + if update_tags: + self.log("CHANGED: tags") + changed = True + self.tags = results['tags'] + + elif self.state == 'absent': + self.log("CHANGED: public ip prefix {0} exists but requested state is 'absent'".format(self.name)) + changed = True + except ResourceNotFoundError: + self.log('Public ip prefix {0} does not exist'.format(self.name)) + if self.state == 'present': + self.log("CHANGED: public IP prefix {0} does not exist but requested state is 'present'".format(self.name)) + changed = True + + self.results['state'] = results + self.results['changed'] = changed + + if self.check_mode: + results['changed'] = True + return results + + if update_tags: + self.results['state'] = self.update_prefix_tags(self.tags) + + elif changed: + if self.state == 'present': + self.log("Create or Update Public IP prefix {0}".format(self.name)) + prefix = self.network_models.PublicIPPrefix( + location=self.location, + public_ip_address_version=self.public_ip_address_version, + prefix_length=self.prefix_length, + zones=self.zones, + tags=self.tags, + sku=self.sku, + ip_tags=self.ip_tags, + custom_ip_prefix=self.custom_ip_prefix + ) + self.results['state'] = self.create_or_update_prefix(prefix) + + elif self.state == 'absent': + self.log('Delete public ip {0}'.format(self.name)) + self.delete_prefix() + + return self.results + + def update_prefix_tags(self, tags): + try: + prefix = self.network_client.public_ip_prefixes.update_tags(self.resource_group, self.name, dict(tags=tags)) + except Exception as exc: + self.fail("Error updating tags {0} - {1}".format(self.name, str(exc))) + return prefix_to_dict(prefix) + + def create_or_update_prefix(self, prefix): + try: + poller = self.network_client.public_ip_prefixes.begin_create_or_update(self.resource_group, self.name, prefix) + prefix = self.get_poller_result(poller) + except Exception as exc: + self.fail("Error creating or updating {0} - {1}".format(self.name, str(exc))) + return prefix_to_dict(prefix) + + def delete_prefix(self): + try: + poller = self.network_client.public_ip_prefixes.begin_delete(self.resource_group, self.name) + self.get_poller_result(poller) + except Exception as exc: + self.fail("Error deleting {0} - {1}".format(self.name, str(exc))) + + self.results['state']['status'] = 'Deleted' + return True + + +def main(): + AzureRMPublicIPPrefix() + + +if __name__ == '__main__': + main() diff --git a/plugins/modules/azure_rm_publicipprefix_info.py b/plugins/modules/azure_rm_publicipprefix_info.py new file mode 100644 index 000000000..f142f3163 --- /dev/null +++ b/plugins/modules/azure_rm_publicipprefix_info.py @@ -0,0 +1,276 @@ +#!/usr/bin/python +# +# Copyright (c) 2024 xuzhang3 (@xuzhang3), Fred-Sun (@Fred-Sun) +# +# GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt) + +from __future__ import absolute_import, division, print_function +__metaclass__ = type + + +DOCUMENTATION = ''' +--- +module: azure_rm_publicipprefix_info + +version_added: "2.2.0" + +short_description: Get public IP prefix facts + +description: + - Get facts for a specific public IP prefix. + - Get all facts for a specific public IP prefixes within a resource group. + +options: + name: + description: + - The name of the public IP prefix. + type: str + resource_group: + description: + - Limit results by resource group. Required when using name parameter. + type: str + tags: + description: + - Limit results by providing a list of tags. Format tags as 'key' or 'key:value'. + type: list + elements: str + +extends_documentation_fragment: + - azure.azcollection.azure + +author: + - xuzhang3 (@xuzhang3) + - Fred-sun (@Fred-sun) +''' + +EXAMPLES = ''' + - name: Get facts for one Public IP Prefix + azure_rm_publicipprefix_info: + resource_group: myResourceGroup + name: publicipprefix + + - name: Get facts for all Public IPs within a resource groups + azure_rm_publicipprefix_info: + resource_group: myResourceGroup + tags: + - key:value +''' + +RETURN = ''' +publicipprefix: + description: + - List of public IP prefixes dicts. + returned: always + type: complex + contains: + id: + description: + - Resource ID. + returned: always + type: str + sample: /subscriptions/xxx---xxxxx/resourceGroups/v-xisuRG/providers/Microsoft.Network/publicIPPrefixes/pipb57dc95224 + name: + description: + - Name of the public IP prefix. + returned: always + type: str + sample: prefix57dc95224 + type: + description: + - Resource type. + returned: always + type: str + sample: "Microsoft.Network/publicIPPrefixes" + location: + description: + - Resource location. + returned: always + type: str + sample: eastus + tags: + description: + - Resource tags. + returned: always + type: dict + sample: { + "delete": "on-exit", + "testing": "testing" + } + public_ip_address_version: + description: + - The public IP address version. + - Possible values are C(IPv4) and C(IPv6). + returned: always + type: str + sample: IPv4 + ip_tags: + description: + - The list of tags associated with the public IP prefixes. + returned: always + type: list + sample: [ + { + "type": "FirstPartyUsage", + "value": "Storage" + } + ] + provisioning_state: + description: + - The provisioning state of the PublicIP Prefix resource. + - Possible values is C(Succeeded). + returned: always + type: str + sample: Succeeded + etag: + description: + - A unique read-only string that changes whenever the resource is updated. + returned: always + type: str + sample: "W/'1905ee13-7623-45b1-bc6b-4a12b2fb9d15'" + sku: + description: + - The public IP prefix SKU. + returned: always + type: dict + sample: {'name': 'standard', 'tier': 'Regional'} + zones: + description: + - A list of availability zones denoting the IP allocated for the resource needs to come from. + returned: always + type: list + sample: ['1', '2'] + prefix_length: + description: + - The Length of the Public IP Prefix. + type: int + returned: always + sample: 29 + extended_location: + description: + - The extended location of the public ip address. + type: str + returned: always + sample: 'eastus2' + custom_ip_prefix: + description: + - The customIpPrefix that this prefix is associated with. + type: dict + returned: always + sample: {} +''' +try: + from azure.core.exceptions import ResourceNotFoundError +except Exception: + # This is handled in azure_rm_common + pass + +from ansible_collections.azure.azcollection.plugins.module_utils.azure_rm_common import AzureRMModuleBase + +AZURE_OBJECT_CLASS = 'PublicIpPrefix' + + +class AzureRMPublicIPPrefixInfo(AzureRMModuleBase): + + def __init__(self): + + self.module_arg_spec = dict( + name=dict(type='str'), + resource_group=dict(type='str'), + tags=dict(type='list', elements='str') + ) + + self.results = dict( + changed=False, + ) + + self.name = None + self.resource_group = None + self.tags = None + + super(AzureRMPublicIPPrefixInfo, self).__init__(self.module_arg_spec, + supports_check_mode=True, + supports_tags=False, + facts_module=True) + + def exec_module(self, **kwargs): + for key in self.module_arg_spec: + setattr(self, key, kwargs[key]) + + result = [] + if self.name is not None and self.resource_group is not None: + result = self.get_item() + elif self.resource_group: + result = self.list_resource_group() + else: + result = self.list_all() + + raw = self.filter(result) + + self.results['publicipprefixes'] = self.format(raw) + + return self.results + + def format(self, raw): + return [self.prefix_to_dict(item) for item in raw] + + def filter(self, response): + return [item for item in response if self.has_tags(item.tags, self.tags)] + + def prefix_to_dict(self, prefix): + result = dict( + id=prefix.id, + name=prefix.name, + tags=prefix.tags, + type=prefix.type, + location=prefix.location, + public_ip_address_version=prefix.public_ip_address_version, + prefix_length=prefix.prefix_length, + provisioning_state=prefix.provisioning_state, + etag=prefix.etag, + zones=prefix.zones, + sku=dict(), + ip_tags=dict(), + custom_ip_prefix=dict(), + extended_location=prefix.extended_location + ) + if prefix.sku: + result['sku']['name'] = prefix.sku.name + result['sku']['tier'] = prefix.sku.tier + if prefix.custom_ip_prefix: + result['custom_ip_prefix']['id'] = prefix.custom_ip_prefix.id + if prefix.ip_tags: + result['ip_tags'] = [dict(type=x.ip_tag_type, value=x.tag) for x in prefix.ip_tags] + return result + + def get_item(self): + self.log('Get properties for {0}'.format(self.name)) + item = None + try: + item = self.network_client.public_ip_prefixes.get(self.resource_group, self.name) + except ResourceNotFoundError: + pass + return [item] if item else [] + + def list_resource_group(self): + self.log('List items in resource groups') + try: + response = self.network_client.public_ip_prefixes.list(self.resource_group) + except ResourceNotFoundError as exc: + self.fail("Error listing items in resource groups {0} - {1}".format(self.resource_group, str(exc))) + return response + + def list_all(self): + self.log('List all items') + try: + response = self.network_client.public_ip_prefixes.list_all() + except ResourceNotFoundError as exc: + self.fail("Error listing all items - {0}".format(str(exc))) + return response + + +def main(): + AzureRMPublicIPPrefixInfo() + + +if __name__ == '__main__': + main() diff --git a/pr-pipelines.yml b/pr-pipelines.yml index 3727c191f..bfe8b6326 100644 --- a/pr-pipelines.yml +++ b/pr-pipelines.yml @@ -93,6 +93,7 @@ parameters: - "azure_rm_privatelinkservice" - "azure_rm_privatednszonelink" - "azure_rm_publicipaddress" + - "azure_rm_publicipprefix" - "azure_rm_proximityplacementgroup" - "azure_rm_rediscache" - "azure_rm_resource" diff --git a/tests/integration/targets/azure_rm_publicipprefix/aliases b/tests/integration/targets/azure_rm_publicipprefix/aliases new file mode 100644 index 000000000..aa77c071a --- /dev/null +++ b/tests/integration/targets/azure_rm_publicipprefix/aliases @@ -0,0 +1,3 @@ +cloud/azure +shippable/azure/group2 +destructive diff --git a/tests/integration/targets/azure_rm_publicipprefix/meta/main.yml b/tests/integration/targets/azure_rm_publicipprefix/meta/main.yml new file mode 100644 index 000000000..95e1952f9 --- /dev/null +++ b/tests/integration/targets/azure_rm_publicipprefix/meta/main.yml @@ -0,0 +1,2 @@ +dependencies: + - setup_azure diff --git a/tests/integration/targets/azure_rm_publicipprefix/tasks/main.yml b/tests/integration/targets/azure_rm_publicipprefix/tasks/main.yml new file mode 100644 index 000000000..d229bc68b --- /dev/null +++ b/tests/integration/targets/azure_rm_publicipprefix/tasks/main.yml @@ -0,0 +1,102 @@ +- name: Create random variable + ansible.builtin.set_fact: + rpfx: "{{ resource_group | hash('md5') | truncate(7, True, '') }}{{ 1000 | random }}" + +- name: Create public ip prefix (Check mode) + azure_rm_publicipprefix: + resource_group: "{{ resource_group }}" + name: "pipprefix{{ rpfx }}" + zones: + - 1 + public_ip_address_version: IPV4 + prefix_length: 29 + sku: + name: Standard + tier: Regional + tags: + testing: testing + check_mode: true + +- name: Create public ip prefix + azure_rm_publicipprefix: + resource_group: "{{ resource_group }}" + name: "pipprefix{{ rpfx }}" + zones: + - 1 + public_ip_address_version: IPV4 + prefix_length: 29 + sku: + name: Standard + tier: Regional + tags: + testing: testing + register: output + +- name: Assert the public IP prefix is well created + ansible.builtin.assert: + that: + - output.changed + +- name: Create public ip prefix (Idempotent test) + azure_rm_publicipprefix: + resource_group: "{{ resource_group }}" + name: "pipprefix{{ rpfx }}" + zones: + - 1 + public_ip_address_version: IPV4 + prefix_length: 29 + sku: + name: Standard + tier: Regional + tags: + testing: testing + register: output + +- name: Assert the public IP prefix no change + ansible.builtin.assert: + that: + - not output.changed + +- name: Update public ip prefix (Update tags) + azure_rm_publicipprefix: + resource_group: "{{ resource_group }}" + name: "pipprefix{{ rpfx }}" + zones: + - 1 + public_ip_address_version: IPV4 + prefix_length: 29 + sku: + name: Standard + tier: Regional + tags: + testing2: testing2 + register: output + +- name: Assert the public IP prefix change + ansible.builtin.assert: + that: + - output.changed + +- name: Gather facts for a public ip prefix + azure_rm_publicipprefix_info: + resource_group: "{{ resource_group }}" + name: "pipprefix{{ rpfx }}" + register: output + +- name: Assert the public IP prefix facts + ansible.builtin.assert: + that: + - output.publicipprefixes[0].tags | length == 2 + - output.publicipprefixes[0].prefix_length == 29 + +- name: Delete the public IP prefix + azure_rm_publicipprefix: + resource_group: "{{ resource_group }}" + name: "pipprefix{{ rpfx }}" + state: absent + register: output + +- name: Assert the public IP prefix deleted + ansible.builtin.assert: + that: + - output.changed From f0074542846605769d982cd89652726ca2ed4dc3 Mon Sep 17 00:00:00 2001 From: Fred-sun Date: Wed, 10 Jan 2024 22:05:28 +0800 Subject: [PATCH 2/9] Fix ansible lint error --- plugins/modules/azure_rm_publicipprefix.py | 38 +++++++++---------- .../modules/azure_rm_publicipprefix_info.py | 20 +++++----- 2 files changed, 29 insertions(+), 29 deletions(-) diff --git a/plugins/modules/azure_rm_publicipprefix.py b/plugins/modules/azure_rm_publicipprefix.py index 9637cc037..6ad7981a8 100644 --- a/plugins/modules/azure_rm_publicipprefix.py +++ b/plugins/modules/azure_rm_publicipprefix.py @@ -118,25 +118,25 @@ ''' EXAMPLES = ''' - - name: Create a public ip prefix - azure_rm_publicipprefix: - resource_group: myResourceGroup - name: my_public_ip - public_ip_address_version: IPV4 - prefix_length: 29 - sku: - name: Standard - tier: Regional - zones: - - 1 - tags: - key1: value1 - - - name: Delete public ip prefix - azure_rm_publicipprefix: - resource_group: myResourceGroup - name: my_public_ipprefix - state: absent +- name: Create a public ip prefix + azure_rm_publicipprefix: + resource_group: myResourceGroup + name: my_public_ip + public_ip_address_version: IPV4 + prefix_length: 29 + sku: + name: Standard + tier: Regional + zones: + - 1 + tags: + key1: value1 + +- name: Delete public ip prefix + azure_rm_publicipprefix: + resource_group: myResourceGroup + name: my_public_ipprefix + state: absent ''' RETURN = ''' diff --git a/plugins/modules/azure_rm_publicipprefix_info.py b/plugins/modules/azure_rm_publicipprefix_info.py index f142f3163..6dd8440f8 100644 --- a/plugins/modules/azure_rm_publicipprefix_info.py +++ b/plugins/modules/azure_rm_publicipprefix_info.py @@ -44,16 +44,16 @@ ''' EXAMPLES = ''' - - name: Get facts for one Public IP Prefix - azure_rm_publicipprefix_info: - resource_group: myResourceGroup - name: publicipprefix - - - name: Get facts for all Public IPs within a resource groups - azure_rm_publicipprefix_info: - resource_group: myResourceGroup - tags: - - key:value +- name: Get facts for one Public IP Prefix + azure_rm_publicipprefix_info: + resource_group: myResourceGroup + name: publicipprefix + +- name: Get facts for all Public IPs within a resource groups + azure_rm_publicipprefix_info: + resource_group: myResourceGroup + tags: + - key:value ''' RETURN = ''' From f9f8bc802b7766ab124dc08a823f41b2821fb235 Mon Sep 17 00:00:00 2001 From: Fred-sun Date: Wed, 10 Jan 2024 22:25:24 +0800 Subject: [PATCH 3/9] fix sanity error --- plugins/modules/azure_rm_publicipprefix.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/plugins/modules/azure_rm_publicipprefix.py b/plugins/modules/azure_rm_publicipprefix.py index 6ad7981a8..8beebeaa7 100644 --- a/plugins/modules/azure_rm_publicipprefix.py +++ b/plugins/modules/azure_rm_publicipprefix.py @@ -55,7 +55,7 @@ - Standard tier: description: - - Tier of a public IP prefix SKU. + - Tier of a public IP prefix SKU. type: str choices: - Regional @@ -67,7 +67,7 @@ suboptions: id: descritption: - - + - Resource ID. type: str extended_location: description: From dae2f9519c97c79f545a502a43ac695f2b8f546b Mon Sep 17 00:00:00 2001 From: Fred-sun Date: Wed, 10 Jan 2024 23:32:34 +0800 Subject: [PATCH 4/9] fix sanity error --- plugins/modules/.azure_rm_virtualwan.py.swp | Bin 0 -> 16384 bytes plugins/modules/azure_rm_publicipprefix.py | 8 ++++---- 2 files changed, 4 insertions(+), 4 deletions(-) create mode 100644 plugins/modules/.azure_rm_virtualwan.py.swp diff --git a/plugins/modules/.azure_rm_virtualwan.py.swp b/plugins/modules/.azure_rm_virtualwan.py.swp new file mode 100644 index 0000000000000000000000000000000000000000..4bbd81c231d1219cf7c8540948bd182504802caa GIT binary patch literal 16384 zcmeI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34E6ICC?#E)z3Qsz%Q>_iXPF7QWyNmZRLZ z88)NyFtMdX}De zmMV;I=IdGWe@z=kvZDwOu1q1OoP!?q>15<6h0=NNy`V>_fZg;xF3pjI=>M40GM%h08Z8z+CcvA#Xn*zTi z5F0zX1pT_~c8@Br@aBOp;G5S|2)LV-x1ZO2Jleq?ct9}$sA+>oEhnqlCws?g6!@5#&+NjqzH#ckTD67e&T}LS@k=EOBSVgIt+EU}} zc2qwj;I2peYyv0Sz7vmz$gt+;Mc)s;@CLD3fs|pn-m9On-7r@9ym^=fx?tehjPmc zcB8?iLfD_l%iCO()9gvoIxxmR`iYv0Z6mB;k)NL0E6+9WhG{SA7h9f)Rd-)_QL1^F zMgClpAVhLgKCt_1>$==~{{{%HKn|xOY}M$~pln8TM1&@X*%NlWFu;nu)>lnhYYR12 zjFq(-P1VH*6U+*#l5G>*lLk?PV>2Qw3|r&Srp=kFiFQGHiS$ql)^dYztYXxo!*5!D z6*o(}k#mDTJo!ka){;rbRb$w#9~0x_#eVBLL)o@fx=M)-7F<-RwDJ9j>T8u=UAY`+-aBdo0Q6<;^c1V6sKbV3)$46$uo zqdRs_oY+m^3KSNYX7)Cvzg-mU8Z_4DJo+33jpUwtpk}OQtnRS;O2128)CZaIYYgbf z#4(%SS2>dN>P%gi9MF2i8lx6}>Fa-Rx}vwnD-WVmwtvj(6h^mcwEcn&Grc2Jv~)Me zVJ<_Tq|(EuTM1QGY|&eHqqgvMn*%Q!ym^YX>ym>rcz6WlKDoc0f&l1=e&($U?~H?; ziHkJ@(J=wi)0KV!wVS6t&?Q1!5q_ESCB2rX%|FlAX0@v-3U75`2h0fjjkA9PN!|Be literal 0 HcmV?d00001 diff --git a/plugins/modules/azure_rm_publicipprefix.py b/plugins/modules/azure_rm_publicipprefix.py index 8beebeaa7..daa89ea32 100644 --- a/plugins/modules/azure_rm_publicipprefix.py +++ b/plugins/modules/azure_rm_publicipprefix.py @@ -48,7 +48,7 @@ type: dict suboptions: name: - descritpion: + description: - Name of a public IP prefix SKU. type: str choices: @@ -81,11 +81,11 @@ suboptions: ip_tag_type: description: - - The IP tag type. Example: FirstPartyUsage. + - The IP tag type. Example as FirstPartyUsage. type: str tag: description: - - The value of the IP tag associated with the public IP. Example: SQL. + - The value of the IP tag associated with the public IP. Example as SQL. type: str public_ip_address_version: description: @@ -93,7 +93,6 @@ choices: - IPV4 - IPV6 - default: ipv4 zones: description: - A list of availability zones denoting the IP prefix allocated for the resource needs to come from. @@ -190,6 +189,7 @@ description: - The list of tags associated with the public IP prefixes. returned: always + type: dict ''' from ansible_collections.azure.azcollection.plugins.module_utils.azure_rm_common import AzureRMModuleBase From f9f642d8721b3389adf05c0f74494e2623444437 Mon Sep 17 00:00:00 2001 From: Fred-sun Date: Thu, 11 Jan 2024 07:56:10 +0800 Subject: [PATCH 5/9] Deleted azure_rm_virtualwan.py.swp --- plugins/modules/.azure_rm_virtualwan.py.swp | Bin 16384 -> 0 bytes 1 file changed, 0 insertions(+), 0 deletions(-) delete mode 100644 plugins/modules/.azure_rm_virtualwan.py.swp diff --git a/plugins/modules/.azure_rm_virtualwan.py.swp b/plugins/modules/.azure_rm_virtualwan.py.swp deleted file mode 100644 index 4bbd81c231d1219cf7c8540948bd182504802caa..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 16384 zcmeI3ZHOdC8OKYF=3a6!L@ysiOkD!bF7C|i-X*~d9J<+;yVKj<%f4JLIbze(T{GLc zp02jLdS5QY^Mf852@!%y0*OJ+Pr(=b5J)8P6-f~DDIzF{2!eu2@*(*ULH$2fT{F`& zH+y&92_oI_+n%Yem#3bm>glIyYMYZMk1gwDy+Lv8Z<-Ucrpxyrve$Jj(avsL_H3(b`YiYj`Xuo zq;;L@BpqiXNL1#An{HH#w?|fAJ}5O%YG6kV>|=)xPEAsl+iyF-KXCKfj=9T+r3Ok3 zlo}{CP->vmK&gRJ1EmH^4g7y;K*iUwbLi5$^KN}HzrSnX{;&Ls^Yrrr&;OY}Ka;1w z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G{SA7h9f)Rd-)_QL1^F zMgClpAVhLgKCt_1>$==~{{{%HKn|xOY}M$~pln8TM1&@X*%NlWFu;nu)>lnhYYR12 zjFq(-P1VH*6U+*#l5G>*lLk?PV>2Qw3|r&Srp=kFiFQGHiS$ql)^dYztYXxo!*5!D z6*o(}k#mDTJo!ka){;rbRb$w#9~0x_#eVBLL)o@fx=M)-7F<-RwDJ9j>T8u=UAY`+-aBdo0Q6<;^c1V6sKbV3)$46$uo zqdRs_oY+m^3KSNYX7)Cvzg-mU8Z_4DJo+33jpUwtpk}OQtnRS;O2128)CZaIYYgbf z#4(%SS2>dN>P%gi9MF2i8lx6}>Fa-Rx}vwnD-WVmwtvj(6h^mcwEcn&Grc2Jv~)Me zVJ<_Tq|(EuTM1QGY|&eHqqgvMn*%Q!ym^YX>ym>rcz6WlKDoc0f&l1=e&($U?~H?; ziHkJ@(J=wi)0KV!wVS6t&?Q1!5q_ESCB2rX%|FlAX0@v-3U75`2h0fjjkA9PN!|Be From 804af4af37238e62d313bb03d12f679714ec6798 Mon Sep 17 00:00:00 2001 From: Fred-sun Date: Thu, 11 Jan 2024 10:47:30 +0800 Subject: [PATCH 6/9] Fix sanity error 03 --- plugins/modules/azure_rm_publicipprefix.py | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/plugins/modules/azure_rm_publicipprefix.py b/plugins/modules/azure_rm_publicipprefix.py index daa89ea32..6585eeade 100644 --- a/plugins/modules/azure_rm_publicipprefix.py +++ b/plugins/modules/azure_rm_publicipprefix.py @@ -62,11 +62,11 @@ - Global custom_ip_prefix: description: - - The customIpPrefix that this prefix is associated with. + - The Custom IP prefix that this prefix is associated with. type: dict suboptions: - id: - descritption: + id: + description: - Resource ID. type: str extended_location: @@ -90,6 +90,7 @@ public_ip_address_version: description: - The public IP address version. + type: str choices: - IPV4 - IPV6 @@ -102,7 +103,7 @@ - '1' - '2' - '3' - prefix_lenth: + prefix_length: description: - The Length of the Public IP Prefix. type: int From 2d6482112f771b68ff56f7936751b684b7cfbad3 Mon Sep 17 00:00:00 2001 From: Fred-sun Date: Mon, 15 Jan 2024 18:08:01 +0800 Subject: [PATCH 7/9] new return value --- plugins/modules/azure_rm_publicipprefix_info.py | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/plugins/modules/azure_rm_publicipprefix_info.py b/plugins/modules/azure_rm_publicipprefix_info.py index 6dd8440f8..4dd26ba86 100644 --- a/plugins/modules/azure_rm_publicipprefix_info.py +++ b/plugins/modules/azure_rm_publicipprefix_info.py @@ -231,8 +231,13 @@ def prefix_to_dict(self, prefix): sku=dict(), ip_tags=dict(), custom_ip_prefix=dict(), + ip_prefix=prefix.ip_prefix, + resource_guid=prefix.resource_guid, + public_ip_addresses=dict(), extended_location=prefix.extended_location ) + if prefix.public_ip_addresses: + result['public_ip_addresses']['id'] = prefix.public_ip_addresses.id if prefix.sku: result['sku']['name'] = prefix.sku.name result['sku']['tier'] = prefix.sku.tier From 8ea190c46d6520d2d81487c6a7120526ad126119 Mon Sep 17 00:00:00 2001 From: Fred-sun Date: Mon, 15 Jan 2024 21:23:34 +0800 Subject: [PATCH 8/9] Modify return value's type --- .../modules/azure_rm_publicipprefix_info.py | 21 ++++++++++++++++--- 1 file changed, 18 insertions(+), 3 deletions(-) diff --git a/plugins/modules/azure_rm_publicipprefix_info.py b/plugins/modules/azure_rm_publicipprefix_info.py index 4dd26ba86..c8cf0eff1 100644 --- a/plugins/modules/azure_rm_publicipprefix_info.py +++ b/plugins/modules/azure_rm_publicipprefix_info.py @@ -157,6 +157,21 @@ type: dict returned: always sample: {} + public_ip_addresses: + description: + - The list of all referenced PublicIPAddresses. + type: list + sample: [] + resource_guid: + description: + - The resource GUID property of the public IP prefix resource. + type: str + sample: "47cafa04-851d-4579-894d-74ad6afe3233" + ip_prefix: + description: + - The allocated Prefix. + type: str + sample: 20.199.95.80/29 ''' try: from azure.core.exceptions import ResourceNotFoundError @@ -229,15 +244,15 @@ def prefix_to_dict(self, prefix): etag=prefix.etag, zones=prefix.zones, sku=dict(), - ip_tags=dict(), + ip_tags=list(), custom_ip_prefix=dict(), ip_prefix=prefix.ip_prefix, resource_guid=prefix.resource_guid, - public_ip_addresses=dict(), + public_ip_addresses=list(), extended_location=prefix.extended_location ) if prefix.public_ip_addresses: - result['public_ip_addresses']['id'] = prefix.public_ip_addresses.id + result['public_ip_addresses'] = [x.id for x in prefix.public_ip_addresses] if prefix.sku: result['sku']['name'] = prefix.sku.name result['sku']['tier'] = prefix.sku.tier From d5584e6ece4c4c2ad3c1198b406e85771c995b07 Mon Sep 17 00:00:00 2001 From: Fred-sun Date: Mon, 22 Jan 2024 09:46:26 +0800 Subject: [PATCH 9/9] Added the return attribute of azure_rm_publicprefix.py --- plugins/modules/azure_rm_publicipprefix.py | 24 +++++++++++++++++++++- 1 file changed, 23 insertions(+), 1 deletion(-) diff --git a/plugins/modules/azure_rm_publicipprefix.py b/plugins/modules/azure_rm_publicipprefix.py index 6585eeade..90bfafc41 100644 --- a/plugins/modules/azure_rm_publicipprefix.py +++ b/plugins/modules/azure_rm_publicipprefix.py @@ -190,7 +190,24 @@ description: - The list of tags associated with the public IP prefixes. returned: always + type: list + sample: [{'type': 'FirstPartyUsage', 'value': 'Storage'}] + resource_guid: + description: + - The resource GUID property of the public IP prefix resource. + type: str + sample: "47cafa04-851d-4579-894d-74ad6afe3233" + custom_ip_prefix: + description: + - The customIpPrefix that this prefix is associated with. type: dict + returned: always + sample: {} + public_ip_addresses: + description: + - The list of all referenced PublicIPAddresses. + type: list + sample: [] ''' from ansible_collections.azure.azcollection.plugins.module_utils.azure_rm_common import AzureRMModuleBase @@ -215,10 +232,15 @@ def prefix_to_dict(prefix): etag=prefix.etag, zones=prefix.zones, sku=dict(), - ip_tags=dict(), + ip_tags=list(), custom_ip_prefix=dict(), + ip_prefix=prefix.ip_prefix, + resource_guid=prefix.resource_guid, + public_ip_addresses=list(), extended_location=prefix.extended_location ) + if prefix.public_ip_addresses: + result['public_ip_addresses'] = [x.id for x in prefix.public_ip_addresses] if prefix.sku: result['sku']['name'] = prefix.sku.name result['sku']['tier'] = prefix.sku.tier