From 1ed3e40e90dda5b7c9a4fffba357aadd7fe0bf16 Mon Sep 17 00:00:00 2001 From: milkmix Date: Wed, 13 Mar 2019 18:41:16 +0100 Subject: [PATCH] modified json parsing part for zones --- requirements.txt | 3 +-- roles/cloud-cloudstack/tasks/main.yml | 4 ++-- roles/cloud-cloudstack/tasks/prompts.yml | 10 +++++++--- 3 files changed, 10 insertions(+), 7 deletions(-) diff --git a/requirements.txt b/requirements.txt index 9f178056..925fd58b 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,2 +1 @@ -ansible==2.5.2 -jmespath==0.9.4 \ No newline at end of file +ansible==2.5.2 \ No newline at end of file diff --git a/roles/cloud-cloudstack/tasks/main.yml b/roles/cloud-cloudstack/tasks/main.yml index 2a3b9062..792003d7 100644 --- a/roles/cloud-cloudstack/tasks/main.yml +++ b/roles/cloud-cloudstack/tasks/main.yml @@ -10,8 +10,8 @@ - set_fact: algo_region: >- {% if region is defined %}{{ region }} - {%- elif _algo_region.user_input is defined and _algo_region.user_input != "" %}{{ cs_zones[_algo_region.user_input | int -1 ] }} - {%- else %}{{ cs_zones[default_region | int - 1] }}{% endif %} + {%- elif _algo_region.user_input is defined and _algo_region.user_input != "" %}{{ cs_zones[_algo_region.user_input | int -1 ]['name'] }} + {%- else %}{{ cs_zones[default_region | int - 1]['name'] }}{% endif %} - name: Security group created cs_securitygroup: diff --git a/roles/cloud-cloudstack/tasks/prompts.yml b/roles/cloud-cloudstack/tasks/prompts.yml index e16c48bb..b10c305d 100644 --- a/roles/cloud-cloudstack/tasks/prompts.yml +++ b/roles/cloud-cloudstack/tasks/prompts.yml @@ -6,20 +6,24 @@ - name: Parse zones from output set_fact: - cs_zones: "{{cs_zones_list.stdout | from_json | json_query('zone[*].name')}}" + _cs_zones: "{{cs_zones_list.stdout | from_json }}" + - name: Extract zones from output + set_fact: + cs_zones: "{{ _cs_zones.zone | sort(attribute='name') }}" + - name: Set the default zone set_fact: default_zone: >- {% for z in cs_zones %} - {%- if z == "ch-gva-2" %}{{ loop.index }}{% endif %} + {%- if z['name'] == "ch-gva-2" %}{{ loop.index }}{% endif %} {%- endfor %} - pause: prompt: | What zone should the server be located in? {% for z in cs_zones %} - {{ loop.index }}. {{ z }} + {{ loop.index }}. {{ z['name'] }} {% endfor %} Enter the number of your desired zone