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/20201022121125.563414e7%40gmail.com.

Attachment: pgpHF2JUSUTIE.pgp
Description: OpenPGP digital signature

Reply via email to