You will need to place quotation marks around the value you're comparing to 
if it is a string.

This is what worked for me:

     - include_vars: /etc/ansible/anusha/hr/vars/main.yml
       when: components == "xyz"

On Saturday, November 10, 2018 at 11:00:03 PM UTC-6, anushake...@gmail.com 
wrote:
>
> Hi All,
>
>
> I am trying to include vars_Files based on a condition but it is getting 
> failed. Could somone please help.
>
>
>
> *PLAYBOOK:*
>
> ---
>
> - hosts: all
>
>   gather_facts: no
>
>   pre_tasks:
>
>      - include_vars: /etc/ansible/anusha/hr/vars/main.yml
>
>        when: components == xyz
>
>
> *EXECUTION:*
>
> ansible-playbook main.yml -e components=xyz
>
>
> *ERROR:*
>
> FAILED! => {"msg": "The conditional check 'components == XYZ' failed. The 
> error was: error while evaluating conditional (components == XYZ): 
> 'components' is undefined\n\nThe error appears to have been in 
> '/etc/ansible/tesr/xyz/tasks/main.yml': line 6, column 8, but may\nbe 
> elsewhere in the file depending on the exact syntax problem.\n\nThe 
> offending line appears to be:\n\n  pre_tasks:\n     - include_vars: 
> /etc/ansible/anusha/hr/vars/main.yml\n       ^ here\n"}
>

-- 
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 ansible-project+unsubscr...@googlegroups.com.
To post to this group, send email to ansible-project@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/ansible-project/db483434-f479-4a28-be7d-0aeb264a3027%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to