How to run a task conditionally when the user provides some input to vars_prompt
. Problem is, my variable is treated as bool and yes
and no
are never matched.
- hosts: localhost
gather_facts: no
vars_prompt:
- name: "myvar"
prompt: "Do you want to proceed(yes/no)?"
private: no
tasks:
- name: "Set variable"
set_fact:
myvar: "{{ myvar }}"
- name: "Conditional task"
shell: echo "conditional action"
when: "'yes' in myvar"
I am getting following error message when I run above code:
fatal: [localhost]: FAILED! => {}
MSG:
The conditional check ''yes' in myvar' failed. The error was: Unexpected templating type error occurred on ({% if 'yes' in myvar %} True {% else %} False {% endif %}): argument of type 'bool' is not iterable
The error appears to have been in '/home/monk/samples/user.yml': line 14, column 7, but may
be elsewhere in the file depending on the exact syntax problem.
The offending line appears to be:
- name: "Conditional task"
^ here