diff --git a/roles/cloud-cloudstack/tasks/main.yml b/roles/cloud-cloudstack/tasks/main.yml index e1a064f..fbc57e4 100644 --- a/roles/cloud-cloudstack/tasks/main.yml +++ b/roles/cloud-cloudstack/tasks/main.yml @@ -3,14 +3,14 @@ - name: Build python virtual environment import_tasks: venv.yml + - name: Include prompts + import_tasks: prompts.yml + - block: - - name: Include prompts - import_tasks: prompts.yml - - 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 ]['name'] }} + {%- elif _algo_region.user_input is defined and _algo_region.user_input | length > 0 %}{{ cs_zones[_algo_region.user_input | int -1 ]['name'] }} {%- else %}{{ cs_zones[default_zone | int - 1]['name'] }}{% endif %} - name: Security group created @@ -62,7 +62,7 @@ environment: PYTHONPATH: "{{ cloudstack_venv }}/lib/python2.7/site-packages/" CLOUDSTACK_CONFIG: "{{ _cs_config }}" - CLOUDSTACK_REGION: "{% if _cs_region.user_input == '' %}{{ 'exoscale' }}{% else %}{{ _cs_region.user_input }}{% endif %}" + CLOUDSTACK_REGION: "{% if _cs_region.user_input | length <= 0 %}{{ 'exoscale' }}{% else %}{{ _cs_region.user_input }}{% endif %}" rescue: - debug: var=fail_hint diff --git a/roles/cloud-cloudstack/tasks/prompts.yml b/roles/cloud-cloudstack/tasks/prompts.yml index 7e87943..7cb8465 100644 --- a/roles/cloud-cloudstack/tasks/prompts.yml +++ b/roles/cloud-cloudstack/tasks/prompts.yml @@ -1,21 +1,15 @@ --- - block: - - set_fact: - _cs_config: "{{ lookup('env', 'CLOUDSTACK_CONFIG') }}" - - pause: prompt: | Enter path for cloudstack.ini file [~/.cloudstack.ini] register: _cs_config_input - when: _cs_config == "" + when: + - lookup('env', 'CLOUDSTACK_CONFIG') | length <= 0 - set_fact: - _cs_config_input: "{% if _cs_config_input.user_input == ''%}{{ '~/.cloudstack.ini' }}{% else %}{{ _cs_config_input.user_input }}{% endif %}" - when: _cs_config == "" - - - set_fact: - _cs_config: "{% if _cs_config == '' %}{{ _cs_config_input }}{% else %}{{ _cs_config }}{% endif %}" + _cs_config: "{{ _cs_config_input.user_input | default(lookup('env', 'CLOUDSTACK_CONFIG'), true) | default('~/.cloudstack.ini') }}" - pause: prompt: | @@ -26,7 +20,7 @@ - name: Parse zones from output set_fact: _cs_zones: "{{ _cloudstack_zones | from_json }}" - + - name: Extract zones from output set_fact: cs_zones: "{{ _cs_zones | sort(attribute='name') }}"