prompt: We are currently solving the following issue within our repository. Here is the issue text:
  --- BEGIN ISSUE ---
  aws_service_ip_ranges suppport for ipv6
  ### Summary
  
  We are using amazon.aws collection and we noticed that the aws_service_ip_ranges does not have an option to return IPv6 ranges.
  
  ### Issue Type
  
  Feature Idea
  
  ### Component Name
  
  `{ lookup('aws_service_ip_ranges', region='us-west-2', service='ROUTE53_HEALTHCHECKS', ipv6_prefix=True, wantlist=True) }`
  Should return a list of IPv6 addresses that correspond to the Route53 health check. 
  
  
  ### Pull Request
  #430
  
  ### Additional Information
  
  <!--- Paste example playbooks or commands between quotes below -->
  ```
  vars:
    rt53_ranges: "{{ lookup('aws_service_ip_ranges', region='us-west-2', service='ROUTE53_HEALTHCHECKS', ipv6_prefix=True, wantlist=True) }}"
  tasks:
  
  - name: "use list return option and iterate as a loop"
    debug: msg="{% for x in rt53_ranges %}{{ x }} {% endfor %}"
  #    ###"2600:1f14:7ff:f800::/56,2600:1f14:fff:f800::/56"
  ```
  
  
  
  ### Code of Conduct
  
  - [X] I agree to follow the Ansible Code of Conduct
  
  --- END ISSUE ---
  
  Below are some code segments, each from a relevant file. One or more of these files may contain bugs.
  --- BEGIN FILES ---
  Path: `plugins/lookup/aws_service_ip_ranges.py`
  Content:
  ```
  1 # (c) 2016 James Turner <turnerjsm@gmail.com>
  2 # (c) 2017 Ansible Project
  3 # GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt)
  4 from __future__ import (absolute_import, division, print_function)
  5 __metaclass__ = type
  6 
  7 DOCUMENTATION = '''
  8 lookup: aws_service_ip_ranges
  9 author:
  10   - James Turner <turnerjsm@gmail.com>
  11 requirements:
  12   - must have public internet connectivity
  13 short_description: Look up the IP ranges for services provided in AWS such as EC2 and S3.
  14 description:
  15   - AWS publishes IP ranges used on the public internet by EC2, S3, CloudFront, CodeBuild, Route53, and Route53 Health Checking.
  16   - This module produces a list of all the ranges (by default) or can narrow down the list to the specified region or service.
  17 options:
  18   service:
  19     description: 'The service to filter ranges by. Options: EC2, S3, CLOUDFRONT, CODEbUILD, ROUTE53, ROUTE53_HEALTHCHECKS'
  20   region:
  21     description: 'The AWS region to narrow the ranges to. Examples: us-east-1, eu-west-2, ap-southeast-1'
  22 '''
  23 
  24 EXAMPLES = """
  25 vars:
  26   ec2_ranges: "{{ lookup('aws_service_ip_ranges', region='ap-southeast-2', service='EC2', wantlist=True) }}"
  27 tasks:
  28 
  29 - name: "use list return option and iterate as a loop"
  30   debug: msg="{% for cidr in ec2_ranges %}{{ cidr }} {% endfor %}"
  31 # "52.62.0.0/15 52.64.0.0/17 52.64.128.0/17 52.65.0.0/16 52.95.241.0/24 52.95.255.16/28 54.66.0.0/16 "
  32 
  33 - name: "Pull S3 IP ranges, and print the default return style"
  34   debug: msg="{{ lookup('aws_service_ip_ranges', region='us-east-1', service='S3') }}"
  35 # "52.92.16.0/20,52.216.0.0/15,54.231.0.0/17"
  36 """
  37 
  38 RETURN = """
  39 _raw:
  40   description: comma-separated list of CIDR ranges
  41 """
  42 
  43 
  44 import json
  45 
  46 from ansible.errors import AnsibleError
  47 from ansible.module_utils.six.moves.urllib.error import HTTPError
  48 from ansible.module_utils.six.moves.urllib.error import URLError
  49 from ansible.module_utils._text import to_native
  50 from ansible.module_utils.urls import ConnectionError
  51 from ansible.module_utils.urls import open_url
  52 from ansible.module_utils.urls import SSLValidationError
  53 from ansible.plugins.lookup import LookupBase
  54 
  55 
  56 class LookupModule(LookupBase):
  57     def run(self, terms, variables, **kwargs):
  58         try:
  59             resp = open_url('https://ip-ranges.amazonaws.com/ip-ranges.json')
  60             amazon_response = json.load(resp)['prefixes']
  61         except getattr(json.decoder, 'JSONDecodeError', ValueError) as e:
  62             # on Python 3+, json.decoder.JSONDecodeError is raised for bad
  63             # JSON. On 2.x it's a ValueError
  64             raise AnsibleError("Could not decode AWS IP ranges: %s" % to_native(e))
  65         except HTTPError as e:
  66             raise AnsibleError("Received HTTP error while pulling IP ranges: %s" % to_native(e))
  67         except SSLValidationError as e:
  68             raise AnsibleError("Error validating the server's certificate for: %s" % to_native(e))
  69         except URLError as e:
  70             raise AnsibleError("Failed look up IP range service: %s" % to_native(e))
  71         except ConnectionError as e:
  72             raise AnsibleError("Error connecting to IP range service: %s" % to_native(e))
  73 
  74         if 'region' in kwargs:
  75             region = kwargs['region']
  76             amazon_response = (item for item in amazon_response if item['region'] == region)
  77         if 'service' in kwargs:
  78             service = str.upper(kwargs['service'])
  79             amazon_response = (item for item in amazon_response if item['service'] == service)
  80 
  81         return [item['ip_prefix'] for item in amazon_response]
  82
  ```
  --- END FILES ---
  
  Please first localize the bug based on the issue statement, and then generate a patch according to the `git diff` format fenced by three backticks.
  
  Here is an example:
  
  ```diff
  diff --git a/examples/server_async.py b/examples/server_async.py
  --- a/examples/server_async.py
  +++ b/examples/server_async.py
  @@ -313,4 +313,4 @@
   
   
   if __name__ == "__main__":
  -    asyncio.run(run_async_server("."), debug=True)
  +    asyncio.run(run_async_server(), debug=True)
  diff --git a/examples/server_sync.py b/examples/server_sync.py
  --- a/examples/server_sync.py
  +++ b/examples/server_sync.py
  @@ -313,5 +313,5 @@
   
   
   if __name__ == "__main__":
  -    server = run_sync_server(".")
  +    server = run_sync_server()
       server.shutdown()
  
  ```
  
golden_diff: diff --git a/plugins/lookup/aws_service_ip_ranges.py b/plugins/lookup/aws_service_ip_ranges.py
  --- a/plugins/lookup/aws_service_ip_ranges.py
  +++ b/plugins/lookup/aws_service_ip_ranges.py
  @@ -19,6 +19,9 @@
       description: 'The service to filter ranges by. Options: EC2, S3, CLOUDFRONT, CODEbUILD, ROUTE53, ROUTE53_HEALTHCHECKS'
     region:
       description: 'The AWS region to narrow the ranges to. Examples: us-east-1, eu-west-2, ap-southeast-1'
  +  ipv6_prefixes:
  +    description: 'When I(ipv6_prefixes=True) the lookup will return ipv6 addresses instead of ipv4 addresses'
  +    version_added: 2.1.0
   '''
   
   EXAMPLES = """
  @@ -40,7 +43,6 @@
     description: comma-separated list of CIDR ranges
   """
   
  -
   import json
   
   from ansible.errors import AnsibleError
  @@ -55,9 +57,16 @@
   
   class LookupModule(LookupBase):
       def run(self, terms, variables, **kwargs):
  +        if "ipv6_prefixes" in kwargs and kwargs["ipv6_prefixes"]:
  +            prefixes_label = "ipv6_prefixes"
  +            ip_prefix_label = "ipv6_prefix"
  +        else:
  +            prefixes_label = "prefixes"
  +            ip_prefix_label = "ip_prefix"
  +
           try:
               resp = open_url('https://ip-ranges.amazonaws.com/ip-ranges.json')
  -            amazon_response = json.load(resp)['prefixes']
  +            amazon_response = json.load(resp)[prefixes_label]
           except getattr(json.decoder, 'JSONDecodeError', ValueError) as e:
               # on Python 3+, json.decoder.JSONDecodeError is raised for bad
               # JSON. On 2.x it's a ValueError
  @@ -77,5 +86,5 @@
           if 'service' in kwargs:
               service = str.upper(kwargs['service'])
               amazon_response = (item for item in amazon_response if item['service'] == service)
  -
  -        return [item['ip_prefix'] for item in amazon_response]
  +        iprange = [item[ip_prefix_label] for item in amazon_response]
  +        return iprange
  
verification_info: {"golden_diff": "diff --git a/plugins/lookup/aws_service_ip_ranges.py b/plugins/lookup/aws_service_ip_ranges.py\n--- a/plugins/lookup/aws_service_ip_ranges.py\n+++ b/plugins/lookup/aws_service_ip_ranges.py\n@@ -19,6 +19,9 @@\n     description: 'The service to filter ranges by. Options: EC2, S3, CLOUDFRONT, CODEbUILD, ROUTE53, ROUTE53_HEALTHCHECKS'\n   region:\n     description: 'The AWS region to narrow the ranges to. Examples: us-east-1, eu-west-2, ap-southeast-1'\n+  ipv6_prefixes:\n+    description: 'When I(ipv6_prefixes=True) the lookup will return ipv6 addresses instead of ipv4 addresses'\n+    version_added: 2.1.0\n '''\n \n EXAMPLES = \"\"\"\n@@ -40,7 +43,6 @@\n   description: comma-separated list of CIDR ranges\n \"\"\"\n \n-\n import json\n \n from ansible.errors import AnsibleError\n@@ -55,9 +57,16 @@\n \n class LookupModule(LookupBase):\n     def run(self, terms, variables, **kwargs):\n+        if \"ipv6_prefixes\" in kwargs and kwargs[\"ipv6_prefixes\"]:\n+            prefixes_label = \"ipv6_prefixes\"\n+            ip_prefix_label = \"ipv6_prefix\"\n+        else:\n+            prefixes_label = \"prefixes\"\n+            ip_prefix_label = \"ip_prefix\"\n+\n         try:\n             resp = open_url('https://ip-ranges.amazonaws.com/ip-ranges.json')\n-            amazon_response = json.load(resp)['prefixes']\n+            amazon_response = json.load(resp)[prefixes_label]\n         except getattr(json.decoder, 'JSONDecodeError', ValueError) as e:\n             # on Python 3+, json.decoder.JSONDecodeError is raised for bad\n             # JSON. On 2.x it's a ValueError\n@@ -77,5 +86,5 @@\n         if 'service' in kwargs:\n             service = str.upper(kwargs['service'])\n             amazon_response = (item for item in amazon_response if item['service'] == service)\n-\n-        return [item['ip_prefix'] for item in amazon_response]\n+        iprange = [item[ip_prefix_label] for item in amazon_response]\n+        return iprange\n", "issue": "aws_service_ip_ranges suppport for ipv6\n### Summary\r\n\r\nWe are using amazon.aws collection and we noticed that the aws_service_ip_ranges does not have an option to return IPv6 ranges.\r\n\r\n### Issue Type\r\n\r\nFeature Idea\r\n\r\n### Component Name\r\n\r\n`{ lookup('aws_service_ip_ranges', region='us-west-2', service='ROUTE53_HEALTHCHECKS', ipv6_prefix=True, wantlist=True) }`\r\nShould return a list of IPv6 addresses that correspond to the Route53 health check. \r\n\r\n\r\n### Pull Request\r\n#430\r\n\r\n### Additional Information\r\n\r\n<!--- Paste example playbooks or commands between quotes below -->\r\n```\r\nvars:\r\n  rt53_ranges: \"{{ lookup('aws_service_ip_ranges', region='us-west-2', service='ROUTE53_HEALTHCHECKS', ipv6_prefix=True, wantlist=True) }}\"\r\ntasks:\r\n\r\n- name: \"use list return option and iterate as a loop\"\r\n  debug: msg=\"{% for x in rt53_ranges %}{{ x }} {% endfor %}\"\r\n#    ###\"2600:1f14:7ff:f800::/56,2600:1f14:fff:f800::/56\"\r\n```\r\n\r\n\r\n\r\n### Code of Conduct\r\n\r\n- [X] I agree to follow the Ansible Code of Conduct\n", "before_files": [{"content": "# (c) 2016 James Turner <turnerjsm@gmail.com>\n# (c) 2017 Ansible Project\n# GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt)\nfrom __future__ import (absolute_import, division, print_function)\n__metaclass__ = type\n\nDOCUMENTATION = '''\nlookup: aws_service_ip_ranges\nauthor:\n  - James Turner <turnerjsm@gmail.com>\nrequirements:\n  - must have public internet connectivity\nshort_description: Look up the IP ranges for services provided in AWS such as EC2 and S3.\ndescription:\n  - AWS publishes IP ranges used on the public internet by EC2, S3, CloudFront, CodeBuild, Route53, and Route53 Health Checking.\n  - This module produces a list of all the ranges (by default) or can narrow down the list to the specified region or service.\noptions:\n  service:\n    description: 'The service to filter ranges by. Options: EC2, S3, CLOUDFRONT, CODEbUILD, ROUTE53, ROUTE53_HEALTHCHECKS'\n  region:\n    description: 'The AWS region to narrow the ranges to. Examples: us-east-1, eu-west-2, ap-southeast-1'\n'''\n\nEXAMPLES = \"\"\"\nvars:\n  ec2_ranges: \"{{ lookup('aws_service_ip_ranges', region='ap-southeast-2', service='EC2', wantlist=True) }}\"\ntasks:\n\n- name: \"use list return option and iterate as a loop\"\n  debug: msg=\"{% for cidr in ec2_ranges %}{{ cidr }} {% endfor %}\"\n# \"52.62.0.0/15 52.64.0.0/17 52.64.128.0/17 52.65.0.0/16 52.95.241.0/24 52.95.255.16/28 54.66.0.0/16 \"\n\n- name: \"Pull S3 IP ranges, and print the default return style\"\n  debug: msg=\"{{ lookup('aws_service_ip_ranges', region='us-east-1', service='S3') }}\"\n# \"52.92.16.0/20,52.216.0.0/15,54.231.0.0/17\"\n\"\"\"\n\nRETURN = \"\"\"\n_raw:\n  description: comma-separated list of CIDR ranges\n\"\"\"\n\n\nimport json\n\nfrom ansible.errors import AnsibleError\nfrom ansible.module_utils.six.moves.urllib.error import HTTPError\nfrom ansible.module_utils.six.moves.urllib.error import URLError\nfrom ansible.module_utils._text import to_native\nfrom ansible.module_utils.urls import ConnectionError\nfrom ansible.module_utils.urls import open_url\nfrom ansible.module_utils.urls import SSLValidationError\nfrom ansible.plugins.lookup import LookupBase\n\n\nclass LookupModule(LookupBase):\n    def run(self, terms, variables, **kwargs):\n        try:\n            resp = open_url('https://ip-ranges.amazonaws.com/ip-ranges.json')\n            amazon_response = json.load(resp)['prefixes']\n        except getattr(json.decoder, 'JSONDecodeError', ValueError) as e:\n            # on Python 3+, json.decoder.JSONDecodeError is raised for bad\n            # JSON. On 2.x it's a ValueError\n            raise AnsibleError(\"Could not decode AWS IP ranges: %s\" % to_native(e))\n        except HTTPError as e:\n            raise AnsibleError(\"Received HTTP error while pulling IP ranges: %s\" % to_native(e))\n        except SSLValidationError as e:\n            raise AnsibleError(\"Error validating the server's certificate for: %s\" % to_native(e))\n        except URLError as e:\n            raise AnsibleError(\"Failed look up IP range service: %s\" % to_native(e))\n        except ConnectionError as e:\n            raise AnsibleError(\"Error connecting to IP range service: %s\" % to_native(e))\n\n        if 'region' in kwargs:\n            region = kwargs['region']\n            amazon_response = (item for item in amazon_response if item['region'] == region)\n        if 'service' in kwargs:\n            service = str.upper(kwargs['service'])\n            amazon_response = (item for item in amazon_response if item['service'] == service)\n\n        return [item['ip_prefix'] for item in amazon_response]\n", "path": "plugins/lookup/aws_service_ip_ranges.py"}], "after_files": [{"content": "# (c) 2016 James Turner <turnerjsm@gmail.com>\n# (c) 2017 Ansible Project\n# GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt)\nfrom __future__ import (absolute_import, division, print_function)\n__metaclass__ = type\n\nDOCUMENTATION = '''\nlookup: aws_service_ip_ranges\nauthor:\n  - James Turner <turnerjsm@gmail.com>\nrequirements:\n  - must have public internet connectivity\nshort_description: Look up the IP ranges for services provided in AWS such as EC2 and S3.\ndescription:\n  - AWS publishes IP ranges used on the public internet by EC2, S3, CloudFront, CodeBuild, Route53, and Route53 Health Checking.\n  - This module produces a list of all the ranges (by default) or can narrow down the list to the specified region or service.\noptions:\n  service:\n    description: 'The service to filter ranges by. Options: EC2, S3, CLOUDFRONT, CODEbUILD, ROUTE53, ROUTE53_HEALTHCHECKS'\n  region:\n    description: 'The AWS region to narrow the ranges to. Examples: us-east-1, eu-west-2, ap-southeast-1'\n  ipv6_prefixes:\n    description: 'When I(ipv6_prefixes=True) the lookup will return ipv6 addresses instead of ipv4 addresses'\n    version_added: 2.1.0\n'''\n\nEXAMPLES = \"\"\"\nvars:\n  ec2_ranges: \"{{ lookup('aws_service_ip_ranges', region='ap-southeast-2', service='EC2', wantlist=True) }}\"\ntasks:\n\n- name: \"use list return option and iterate as a loop\"\n  debug: msg=\"{% for cidr in ec2_ranges %}{{ cidr }} {% endfor %}\"\n# \"52.62.0.0/15 52.64.0.0/17 52.64.128.0/17 52.65.0.0/16 52.95.241.0/24 52.95.255.16/28 54.66.0.0/16 \"\n\n- name: \"Pull S3 IP ranges, and print the default return style\"\n  debug: msg=\"{{ lookup('aws_service_ip_ranges', region='us-east-1', service='S3') }}\"\n# \"52.92.16.0/20,52.216.0.0/15,54.231.0.0/17\"\n\"\"\"\n\nRETURN = \"\"\"\n_raw:\n  description: comma-separated list of CIDR ranges\n\"\"\"\n\nimport json\n\nfrom ansible.errors import AnsibleError\nfrom ansible.module_utils.six.moves.urllib.error import HTTPError\nfrom ansible.module_utils.six.moves.urllib.error import URLError\nfrom ansible.module_utils._text import to_native\nfrom ansible.module_utils.urls import ConnectionError\nfrom ansible.module_utils.urls import open_url\nfrom ansible.module_utils.urls import SSLValidationError\nfrom ansible.plugins.lookup import LookupBase\n\n\nclass LookupModule(LookupBase):\n    def run(self, terms, variables, **kwargs):\n        if \"ipv6_prefixes\" in kwargs and kwargs[\"ipv6_prefixes\"]:\n            prefixes_label = \"ipv6_prefixes\"\n            ip_prefix_label = \"ipv6_prefix\"\n        else:\n            prefixes_label = \"prefixes\"\n            ip_prefix_label = \"ip_prefix\"\n\n        try:\n            resp = open_url('https://ip-ranges.amazonaws.com/ip-ranges.json')\n            amazon_response = json.load(resp)[prefixes_label]\n        except getattr(json.decoder, 'JSONDecodeError', ValueError) as e:\n            # on Python 3+, json.decoder.JSONDecodeError is raised for bad\n            # JSON. On 2.x it's a ValueError\n            raise AnsibleError(\"Could not decode AWS IP ranges: %s\" % to_native(e))\n        except HTTPError as e:\n            raise AnsibleError(\"Received HTTP error while pulling IP ranges: %s\" % to_native(e))\n        except SSLValidationError as e:\n            raise AnsibleError(\"Error validating the server's certificate for: %s\" % to_native(e))\n        except URLError as e:\n            raise AnsibleError(\"Failed look up IP range service: %s\" % to_native(e))\n        except ConnectionError as e:\n            raise AnsibleError(\"Error connecting to IP range service: %s\" % to_native(e))\n\n        if 'region' in kwargs:\n            region = kwargs['region']\n            amazon_response = (item for item in amazon_response if item['region'] == region)\n        if 'service' in kwargs:\n            service = str.upper(kwargs['service'])\n            amazon_response = (item for item in amazon_response if item['service'] == service)\n        iprange = [item[ip_prefix_label] for item in amazon_response]\n        return iprange\n", "path": "plugins/lookup/aws_service_ip_ranges.py"}]}