AWS List of Availability Zones

27 views
Skip to first unread message

Thomas Stephen Lee

unread,
Dec 5, 2022, 8:28:34 PM12/5/22
to Ansible Project Mailing List
Hi,

I have a small test playbook
https://pastebin.com/kciEWPJ7
The az.out.json is at
https://pastebin.com/BnfaLG1N
What I need is
the region_name and corresponding zone_name(s)
listed like
https://pastebin.com/3HQkN2yf

Please guide.

Thanks
---

Lee

Atul Nasir

unread,
Aug 24, 2023, 11:42:45 PM8/24/23
to Ansible Project
---
- name: Get AWS Availability Zones
  hosts: localhost
  gather_facts: false
  tasks:
    - name: Read JSON file
      slurp:
        src: az.out.json
      register: json_data

    - name: Parse JSON
      set_fact:
        az_data: "{{ json_data.content | b64decode | from_json }}"

    - name: Create list of region and zones
      set_fact:
        region_zones: "{{ region_zones | default([]) + [{ 'region_name': item.region_name, 'zone_names': item.zone_names }] }}"
      loop: "{{ az_data }}"

    - name: Create final output
      set_fact:
        final_output: "{{ region_zones | map(attribute='region_name') | unique | map('extract', region_zones) | list }}"
      run_once: true

    - debug:
        var: final_output
Reply all
Reply to author
Forward
0 new messages