title: Ansible - when conditional not working for vars_prompt at playbook level
body: <p>ansible 2.1.2.0</p>
  
  <p>I have a situation here for which I'm trying to check with you all to see if the solution is even possible with Ansible <code>vars_prompt</code> feature and <code>when</code> conditional.</p>
  
  <p>Ansible has this feature called: <a href="http://docs.ansible.com/ansible/playbooks_prompts.html" rel="nofollow noreferrer">vars_prompt</a> and I want to club this with the <a href="http://docs.ansible.com/ansible/playbooks_conditionals.html#the-when-statement" rel="nofollow noreferrer">when</a> conditional (<code>when: ...</code> which we generally use in tasks at task or playbook level actions)</p>
  
  <p><strong>PS:</strong> My question is <strong>different than this post</strong>: <a href="https://stackoverflow.com/questions/25466675/ansible-to-conditionally-prompt-for-a-variable">Ansible to Conditionally Prompt for a Variable?</a> i.e. my <code>vars:</code> variables are not dependent upon any machine's OS ENV variables, in my case, I just have a simple hardcoded value for <code>vars:</code> variables. I'm also running the when condition at the main playbook level (and not at the task's level).</p>
  
  <p>What I'm trying to do is to prompt a user for entering a variable value, only if at command line, the user has called the <code>ansible-playbook install_tool.yml ... ...</code> with <code>--extra-vars "install_tool=true"</code> </p>
  
  <p>In <strong>workspace/ansible</strong>/install_tool.yml I have:</p>
  
  <pre><code>- hosts: all
    become: true
    gather_facts: false
  
    vars:
      instance: test
      #install_tool: false
      company_api_url: DUMMY_INVALID_URL
  
    vars_prompt:
      - name: "company_api_url"
        prompt: "Enter Company API URL: "
        default: "https://{{ instance }}.company.com"
        private: no
        when: install_tool == "true" and company_api_url == "DUMMY_INVALID_URL"
        # or
        #when: ( "{{ install_tool }}" == "true" and "{{ company_api_url }}" == "DUMMY_INVALID_URL" )
  
    pre_tasks:
      - debug: msg="install_tool = {{ install_tool }} and instance = {{ instance }}" 
        when: install_tool == "true"
  </code></pre>
  
  <p><strong>My question:</strong><br/>
  How can I get the above conditional prompt working (with a valid substituted <code>default</code> value for a prompt variable) <strong>and</strong> also <em>SKIP</em> to prompt a user altogether depending upon the value of <code>install_tool</code> variable?</p>
  
  <p><strong>My understanding:</strong>
  In top level playbook file (<em>install_tool.yml</em>), I'm defining a variable <code>instance</code> with value as <code>test</code>. Why the <code>default</code> value for the vars_prompt section did NOT pick <code>test</code> and substituted its value when it's defined at the playbook level (--OR what if a user is passing <code>instance</code> variable at command line for <strong>ex:</strong> <code>--extra-vars "instance=qa"</code>? In that case, I would want the default value as <code>[https://qa.company.com]</code>, how can I do that)? I don't see any errors while running it for any syntax. </p>
  
  <p>I'm getting the following output (but I was expecting a substituted URL value like: <code>[https://test.company.com]</code>) <strong>and</strong> it's still prompting even when <code>install_tool</code> was set or passed at command line as <code>false</code>:</p>
  
  <p>Running:</p>
  
  <pre><code>$ ansible-playbook -i "localhost," --connection=local install_tool.yml --extra-vars "install_tool=false instance=qa"
  </code></pre>
  
  <p>or</p>
  
  <pre><code>$ ansible-playbook -i inventory -l localhost install_tool.yml --extra-vars "install_tool=false"
  ...
  .....some lines here
  ...
  PLAYBOOK: install_tool.yml *******************************************
  1 plays in install_tool.yml
  Enter Company API URL:  [https://{{ instance }}.company.com]: 
  </code></pre>
  
  <p>As using <code>when: ( "{{ install_tool }}" == "true" and ...)</code> condition within  <code>vars_prompt</code> section, under/for <code>- name: company_api_url</code> variable, it didn't error out for any syntax issues or etc (that means, Ansible doesn't think it's wrong), then <strong>WHY</strong>, Ansible is still prompting me to enter the above <code>vars_prompts</code> variable, even when I'm passing <code>--extra-vars "install_tool=false"</code> <strong>--OR--</strong> if I <strong>uncomment</strong> the line: <code>install_tool: false</code> under <code>vars:</code> section? </p>
  
  <p><strong>PS:</strong> <code>when: ...</code> condition is successfully working for the <code>pre_tasks</code> section i.e. when install_tool is true, it shows the value of those 2 variables and when install_tool is set to false, then it does NOT run the <code>- debug</code> step and skips it (which is expected).</p>
  
  <p>Thanks. </p>