checking if a dynamically selected variable is defined?

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

Here’s a quicker one-liner:

  • assert: { that: ‘foo is defined’ }

Or any other conditional, etc. ‘that’ can also take a list of conditionals.