On 05/21/2014 08:24 AM, Andrew Pashkin wrote:
> I want to make my playbook in a way where process will fail with an
> error if user was not provided required parameters, what is the way to
> do that in Ansible?
>
The default behavior is to fail if using a variable that is not defined.
There is also a configuration option that disables this, and then you
can use "{{ myvar | mandatory }}" to explicitly have the same effect.
Keep in mind, though, that the failure occurs when reaching a task that
uses an undefined variable. If you want to fail before any task is
executed, you could add another task at the top of your tasks that fails
if a mandatory variable is not defined. For example:

tasks:
   - fail: msg="Variable '{{ item }}' is not defined"
     when: item not in hostvars[inventory_hostname]
     with_items:
       - myvariable1
       - myvariable2

-- 
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 [email protected].
To post to this group, send email to [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/ansible-project/537C4FA0.9090301%40yahoo.gr.
For more options, visit https://groups.google.com/d/optout.

Reply via email to