Thank you @Vladimir for the solution. I will test this and share you the
update. value_command is the module, do we need to add the vars in the
module ?
vars:
command_set:
A: ipaddr
B: ifconfig
C: freespace -m
D: yum repolist
vars_prompt:
- name: input
prompt: Please enter the option {{ command_set.keys()|list }}
private: no
tasks:
- name: checking the switchshow
value_command:
command_set:
- debug:
msg: Command {{ command_set[input] }}
when: input in command_set.keys()|list
On Thursday, October 22, 2020 at 3:41:50 PM UTC+5:30 [email protected] wrote:
> On Thu, 22 Oct 2020 02:45:43 -0700 (PDT)
> Sobhan Anavarapu <[email protected]> wrote:
>
> > can we have multiple when conditions in a single task?
> >
> > vars_prompt:
> > - name: input
> > prompt: Please enter the option A,B,C
> > private: no
> > - name: checking the switchshow
> > value_command:
> > command_set:
> > - command: ipaddr
> > - command: ifconfig
> > - command: freespace -m
> > - command: yum repolist
>
> Instead of a list, put the commands into a dictionary. Test with
> debug first. For example
>
> vars:
> command_set:
> A: ipaddr
> B: ifconfig
> C: freespace -m
> D: yum repolist
> vars_prompt:
> - name: input
> prompt: Please enter the option {{ command_set.keys()|list }}
> private: no
> tasks:
> - debug:
> msg: Command {{ command_set[input] }}
> when: input in command_set.keys()|list
>
> You'll be better off with "Data driven programming" in similar
> use-cases. See
> https://stackoverflow.com/questions/1065584/what-is-data-driven-programming
>
> --
> Vladimir Botka
>
--
You received this message because you are subscribed to the Google Groups
"Ansible Project" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To view this discussion on the web visit
https://groups.google.com/d/msgid/ansible-project/cef0682c-316a-4e94-9ca3-5a256f2c96d6n%40googlegroups.com.