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