How to skip role executing in Ansible

Question:

I try to write the playbook.yml for my vagrant machine and I’m faced with the following problem.
Ansible prompt me to set these variables and I set these variables to null/false/no/[just enter], but the roles is executed no matter! How can I prevent this behavior? I just want no actions if no vars are set..

Answer:

I believe the variables will always be defined when you use vars_prompt, so “is defined” will always be true. What you probably want is something along these lines:

Edit: To answer your question, no it does not throw an error. I made a slightly different version and tested it using ansible 1.4.4:

And roles/common/tasks/main.yml contains:

If you run the above example and just hit Enter, accepting the default, then the role is skipped:

But if you run this and enter Y or y when prompted then the role is executed as desired:

Leave a Reply