How to pick certain fields in a loop without tons of “skipping” lines

I’m trying to create an array in Ansible that contains all the AWS regions that are enabled in my account that support FSx for NetApp ONTAP (FSxN).

I know I can use the following to get the list of regions enabled on my account:

    - name: Get all the opted in regions.
      amazon.aws.aws_region_info:
      register: region_info

    - name: Just get region names
      set_fact:
        opted_in_regions: "{{ [item.region_name] + opted_in_regions }}"
      loop: "{{ region_info.regions }}"

But there are times, typically when a new region comes online, that some regions don’t support FSxN.

The only way I have found to know which regions support specific services is to download the price guide from https://api.regional-table.region-services.aws.a2z.com/index.json and look for regions that have “Amazon FSx for NetApp ONTAP” as the “aws:serviceName”. The format for that file is:

{
  "prices": [
    {
      "attributes": {
        "aws:region": "ap-east-1",
        "aws:serviceName": "Amazon Translate",
        "aws:serviceUrl": "https://aws.amazon.com/translate/"
      },
      "id": "translate:ap-east-1"
    },
    {
      "attributes": {
        "aws:region": "ap-northeast-1",
        "aws:serviceName": "Amazon Translate",
        "aws:serviceUrl": "https://aws.amazon.com/translate/"
      },
      "id": "translate:ap-northeast-1"
    },

So, what I did was create variable with the contents of the file:

    - name: Get the capabilities of all regions.
      set_fact:
        regions_capabilities: "{{lookup('ansible.builtin.url', 'https://api.regional-table.region-services.aws.a2z.com/index.json', split_lines=false)}}"

Then the next “task” is to loop through all the values and add to another array the ones that have the specific string in the aws:serviceName field.

    - name: Get the intersection of opted in regions and regions that support FSxN.
      when: item['attributes']['aws:serviceName'] == "Amazon FSx for NetApp ONTAP" and item['attributes']['aws:region'] in opted_in_regions
      set_fact:
        fsxnRegions: "{{ [item['attributes']['aws:region']] + fsxnRegions }}"
      loop: "{{ regions_capabilities.prices }}"

While works, that when: statements generates a LOT (thousands) of skipping... lines in the output. And, it is painfully slow.

So, the question is, is there a better way to create the array of regions that support FSxN? And if not, how can I suppress that skipping message, but ONLY for this task?

Here is the entire Ansible playbook:

# Title: generate report
---
- hosts: localhost
  collections:
    - amazon.aws
  gather_facts: false
  name: Playbook to generate a report on all the FSxNs
  vars:
    fsxnRegions: []
    opted_in_regions: []

  tasks:
    - name: Get all the opted in regions.
      amazon.aws.aws_region_info:
      register: region_info

    - name: Just get region names
      set_fact:
        opted_in_regions: "{{ [item.region_name] + opted_in_regions }}"
      loop: "{{ region_info.regions }}"

    - name: Get the capabilities of all regions.
      set_fact:
        regions_capabilities: "{{lookup('ansible.builtin.url', 'https://api.regional-table.region-services.aws.a2z.com/index.json', split_lines=false)}}"

    - name: Get the intersection of opted in regions and regions that support FSxN.
      when: item['attributes']['aws:serviceName'] == "Amazon FSx for NetApp ONTAP" and item['attributes']['aws:region'] in opted_in_regions
      set_fact:
        fsxnRegions: "{{ [item['attributes']['aws:region']] + fsxnRegions }}"
      loop: "{{ regions_capabilities.prices }}"

    - name: Output
      debug:
        msg: "fsxnRegions={{ fsxnRegions }}"

If I understand you correctly , you can try using selectattr without using the loop

# Title: generate report
---
- hosts: localhost
  collections:
    - amazon.aws
  gather_facts: false
  name: Playbook to generate a report on all the FSxNs
  vars:
    fsxnRegions: []
    opted_in_regions: []

  tasks:
    - name: Get all the opted-in regions
      amazon.aws.aws_region_info:
      register: region_info

    - name: Get region names
      set_fact:
        opted_in_regions: "{{ region_info.regions | map(attribute='region_name') | list }}"

    - name: Get the capabilities of all regions
      set_fact:
        regions_capabilities: "{{ lookup('ansible.builtin.url', 'https://api.regional-table.region-services.aws.a2z.com/index.json', split_lines=false) }}"

    - name: Filter regions that support FSxN and are opted-in
      set_fact:
        fsxnRegions: >-
          {{
            regions_capabilities.prices
            | selectattr("attributes.aws:serviceName", "equalto", "Amazon FSx for NetApp ONTAP")
            | selectattr("attributes.aws:region", "in", opted_in_regions)
            | map(attribute="attributes.aws:region")
            | list
          }}

    - name: Output the FSxN regions
      debug:
        msg: "fsxnRegions={{ fsxnRegions }}"

0

Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa Dịch vụ tổ chức sự kiện 5 sao Thông tin về chúng tôi Dịch vụ sinh nhật bé trai Dịch vụ sinh nhật bé gái Sự kiện trọn gói Các tiết mục giải trí Dịch vụ bổ trợ Tiệc cưới sang trọng Dịch vụ khai trương Tư vấn tổ chức sự kiện Hình ảnh sự kiện Cập nhật tin tức Liên hệ ngay Thuê chú hề chuyên nghiệp Tiệc tất niên cho công ty Trang trí tiệc cuối năm Tiệc tất niên độc đáo Sinh nhật bé Hải Đăng Sinh nhật đáng yêu bé Khánh Vân Sinh nhật sang trọng Bích Ngân Tiệc sinh nhật bé Thanh Trang Dịch vụ ông già Noel Xiếc thú vui nhộn Biểu diễn xiếc quay đĩa Dịch vụ tổ chức tiệc uy tín Khám phá dịch vụ của chúng tôi Tiệc sinh nhật cho bé trai Trang trí tiệc cho bé gái Gói sự kiện chuyên nghiệp Chương trình giải trí hấp dẫn Dịch vụ hỗ trợ sự kiện Trang trí tiệc cưới đẹp Khởi đầu thành công với khai trương Chuyên gia tư vấn sự kiện Xem ảnh các sự kiện đẹp Tin mới về sự kiện Kết nối với đội ngũ chuyên gia Chú hề vui nhộn cho tiệc sinh nhật Ý tưởng tiệc cuối năm Tất niên độc đáo Trang trí tiệc hiện đại Tổ chức sinh nhật cho Hải Đăng Sinh nhật độc quyền Khánh Vân Phong cách tiệc Bích Ngân Trang trí tiệc bé Thanh Trang Thuê dịch vụ ông già Noel chuyên nghiệp Xem xiếc khỉ đặc sắc Xiếc quay đĩa thú vị
Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa
Thiết kế website Thiết kế website Thiết kế website Cách kháng tài khoản quảng cáo Mua bán Fanpage Facebook Dịch vụ SEO Tổ chức sinh nhật