sorry for the mistakes I've made, I'm not Englishman.
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..
---
- name: Deploy Webserver
hosts: webservers
vars_prompt:
run_common: "Run common tasks?"
run_wordpress: "Run Wordpress tasks?"
run_yii: "Run Yii tasks?"
run_mariadb: "Run MariaDB tasks?"
run_nginx: "Run Nginx tasks?"
run_php5: "Run PHP5 tasks?"
roles:
- { role: common, when: run_common is defined }
- { role: mariadb, when: run_mariadb is defined }
- { role: wordpress, when: run_wordpress is defined }
- { role: yii, when: run_yii is defined }
- { role: nginx, when: run_nginx is defined }
- { role: php5, when: run_php5 is defined }
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: