Variable concatenation in when statement

Hi all, I’m running this task:

  • name: assert version

fail:

msg: “‘vmlinuz-{{ kernel_version }}’ not found in default kernel output: ‘{{ default_kernel.stdout }}’”

when: ‘“vmlinuz-{{kernel_version}}” not in default_kernel.stdout’

The key part being that I want to have the fail message concatenate the string literal ‘vmlinuz-’ with the ‘kernel_version’ variable. When I do this, I get this error:

[WARNING]: when statements should not include jinja2 templating delimiters such as {{ }} or {% %}. Found: “vmlinuz-{{kernel_version}}”

not in default_kernel.stdout

What’s the appropriate way to do this?

Answering my own question: I got it to work properly by doing this:

when: ‘“”.join([“vmlinuz-”, kernel_version]) not in default_kernel.stdout’

Would be happy to hear of any other, cleaner ways of doing it.

If it's cleaner or not I leave it to you to decide

when: "'vmlinuz' ~ kernel_version not in default_kernel.stdout"

definitely cleaner IMO, thanks!