The error message states that "'components' is undefined", so assuming "components" are conditionally defined earlier, you'll have to put in another "when" clause to validate it is defined. Something like this:
pre_tasks: - include_vars: /etc/ansible/anusha/hr/vars/main.yml when: * - components is defined* - components == xyz Other examples in the documentation: https://docs.ansible.com/ansible/latest/user_guide/playbooks_conditionals.html#the-when-statement 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/a1a27aec-967b-4864-91fb-6bc2a2f292a4%40googlegroups.com. For more options, visit https://groups.google.com/d/optout.