Using vars_prompt with conditionals in ansible without command line input

Viewed 448

I have the following sample playbook:

---
# ./hello_world.yml

- name: get flag
  hosts: "*"
  gather_facts: true
  vars:
      flag: "yes"
  vars_prompt:
    - name: "flag"
      private: no
      prompt: "Enter flag value" 

    - name: "name"
      private: no
      prompt: "Enter name"
      when: flag=="no"  

  tasks:
    - name: including external variable
      include_vars: name_vars.yml
      when: flag=="yes"

    - debug: msg="Hello, {{name}}"

I want to first ask for the flag from the user, if it's yes, then I read the name variable from another file, and then display it. If the flag is no, I read the user input for name, and display it. But, in the above playbook, if the flag is yes, it still asks for the user input, although it shows the name from the file in the output. Can soomeone help me in rectifying this playbook. TIA.

0 Answers
Related