I'd like to use an if else condition with include in my ansible playbooks. I have the following, which does not perform the check.
- include: do-something.yml if {{version}} >= 1.14 else do-something-else.yml
version is set to 1.13.5 so do-something-else.yml should be run.
The following works but I'd prefer not to have multiple plays run and skipped as it makes the output and logs very busy.
- include: do-something.yml
when: version >= "1.14"
- include: do-something-else.yml
when: version < "1.14"
Here is an example mick.yml, which shows my desired include statement.
---
- include: do-something.yml if {{version}} >= 1.14 else do-something-else.yml
If I run mick.yml I'd expect it to check the version and run do-something-else.yml as version is set to 1.13.5. It does not do so but fails as follows.
ansible-playbook mick.yml
ERROR! Invalid variable name in vars specified for PlaybookInclude: '>' is not a valid variable name