I am new to Ansible .I was wondering how to skip prompt input of a skipped task ?
Below i pressed no. Still it prompted for input for the skipped task
[root@san pure]# ansible-playbook main.yaml
[WARNING]: No inventory was parsed, only implicit localhost is available
[WARNING]: provided hosts list is empty, only localhost is available. Note that the implicit localhost does not match 'all'
Do you want to run volcreation and add it to hostgroup? Enter [yes/no]: no
\Do you want to run hostcreation and add it to hostgroup? Enter [yes/no]: no
PLAY [localhost] ****************************************************************************************************************************************************************************************************************************
TASK [Gathering Facts] **********************************************************************************************************************************************************************************************************************
ok: [localhost]
TASK [set_fact] *****************************************************************************************************************************************************************************************************************************
ok: [localhost]
Enter size [1T]:
Enter hostvolume [ans-vol1]:
Enter hostgroup [ans-hostgroup1]:
[WARNING]: Found variable using reserved name: name
PLAY [Pure Storage storage module examples] *************************************************************************************************************************************************************************************************
TASK [Create new volume] ********************************************************************************************************************************************************************************************************************
skipping: [localhost]
TASK [Create new hostgroup and connect hosts and volumes] **********************************************************************************************************************************************************************************
skipping: [localhost]
Enter hostname [ans-host1]:
Enter adaptor [22:22:22:22:22:22:22:22]:
Enter protocol [fc]:
Enter hostgroup [ans-hostgroup1]:
PLAY [Pure Storage storage module examples] *************************************************************************************************************************************************************************************************
TASK [Create new host] *********************************************************************************************************************************************************************************************************************
skipping: [localhost]
TASK [Create new hostgroup and connect hosts and volumes] **********************************************************************************************************************************************************************************
skipping: [localhost]
PLAY RECAP **********************************************************************************************************************************************************************************************************************************
localhost : ok=2 changed=0 unreachable=0 failed=0 skipped=4 rescued=0 ignored=0
[root@san pure]#
Here is the main file
[root@san pure]# cat main.yaml
---
- hosts: localhost
vars_prompt:
- name: "volcreation"
prompt: "Do you want to run volcreation and add it to hostgroup? Enter [yes/no]"
private: no
- name: "hostcreation"
prompt: "Do you want to run hostcreation and add it to hostgroup? Enter [yes/no]"
private: no
tasks:
- set_fact:
volcreation: "{{volcreation}}"
hostcreation: "{{hostcreation}}"
- name: run the volcreation yaml file
import_playbook: volcreation.yaml
when: volcreation == True
- name: run the hostcreation yaml file
import_playbook: hostcreation.yaml
when: hostcreation == True
Here is the subfile
[root@san pure]# cat volcreation.yaml
---
- hosts: localhost
name: Pure Storage storage module examples
gather_facts: no
vars_prompt:
- name: "size"
prompt: "Enter size"
private: no
default: "1T"
- name: "name"
prompt: "Enter hostvolume"
private: no
default: "ans-vol1"
- name: "hostgroup"
prompt: "Enter hostgroup"
private: no
default: "ans-hostgroup1"
tasks:
- name: Create new volume
purefa_volume:
name="{{ name }}"
size="{{ size }}"
- name: Create new hostgroup and connect hosts and volumes
purefa_hg:
hostgroup="{{ hostgroup }}"
volume="{{ name }}"