Here's a quicker one-liner:
- assert: { that: 'foo is defined' }
Or any other conditional, etc. 'that' can also take a list of conditionals.
On Fri, Aug 29, 2014 at 12:30 PM, Dylan Martin <[email protected]> wrote:
> Hi all.
>
> I often write plays that require extra vars. eg "ansible-playbook user -e
> user=bob"
>
> In that play, I'll start off with
>
> - fail: msg="You forgot to set the user variable"
> when: user is not defined or user == ""
>
> And I was thinking it might be nice to write an external, reusable play
> that would be called like this:
>
> - include: check_defined.yaml checkvar=user
>
> and look something like this
>
> ----
> - hosts: all
> tasks:
> - fail: msg="{{ you forgot to specify a checkvar }}"
> when: checkvar is not defined or checkvar == ""
> - fail: msg="you forgot to set {{ checkvar }}"
> when: ?????? is not defined or ?????? == ""
>
> The first fail is just to catch myself if I include check_defined.yaml
> without setting checkvar
> the second fail is the thing I actually am curious about. The ????? are
> the bits I don't know how to do.
>
> Okay, I admit this is pretty silly, since I could write the is not defined
> checks for about 20 playbooks in the time it took to write this email. And
> including the play is one line when the play itself ( or task) is 2. But
> still, I think I'd understand ansible and jinja2 better if I knew the
> answer to this.
>
> Thanks
> -Dylan
>
> --
> 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/a1dd35e3-6ea3-4482-991f-e979456bdc28%40googlegroups.com
> <https://groups.google.com/d/msgid/ansible-project/a1dd35e3-6ea3-4482-991f-e979456bdc28%40googlegroups.com?utm_medium=email&utm_source=footer>
> .
> For more options, visit https://groups.google.com/d/optout.
>
--
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/CA%2BnsWgxNH%3DhN0P9Qj%2BBWQ7qKvM5pn-kA%2BYUYkdPWb5afG7VtwA%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.