modified json parsing part for zones

This commit is contained in:
milkmix 2019-03-13 18:41:16 +01:00 committed by milkmix
parent 2e51d8b744
commit 1ed3e40e90
3 changed files with 10 additions and 7 deletions

View file

@ -1,2 +1 @@
ansible==2.5.2
jmespath==0.9.4
ansible==2.5.2

View file

@ -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:

View file

@ -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