when_string and only_if don't seem to be expanding variables

Hello,

I’m working on a playbook to install several packages and would like to add logic to handle installing to both Debian-based and RHEL-based distros. To this end, I’ve attempted to use “when_string” and “only_if” to check facts gathered from the servers to determine if apt or yum should be used. However, whenever I add when_string or only_if (separately, not at the same time) to the tasks below, ansible skips these tasks. I’ve tried running ansible-playbook with -vvvv to get more verbose output, but the only output I am able to see is that it skips the task:

TASK: [Install required packages (apt)] ***************************************

skipping: [ubuntuserver]

Here is the playbook:

So, when_string and only_if are hopelessly old and deprecated.

The answer is to use “when:” everywhere, and that’s why it’s been the only thing documented in the docs for a couple of releases.

Michael,

Thanks, I was able to get it working with “when:”. On a related note, are all variables within “when:” referred to without a preceding $ ?

Thanks,

Andrew

“On a related note, are all variables within “when:” referred to without a preceding $ ?”

Yeah, the template stuff is unnecessary because we actually evaluate the whole “when” line using the template engine internally.

The same goes true for “with_items” and the other “with_” statements.

Thanks for the clarification.