# Variable concatenation in when statement

**URL:** <https://forum.ansible.com/t/variable-concatenation-in-when-statement/28458>\
**Category:** Ansible Project\
**Created:** [August 29, 2018, 1:52pm UTC](https://forum.ansible.com/t/variable-concatenation-in-when-statement/28458 "2018-08-29T13:52:21Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![yaakov.kuperman](https://avatars.discourse-cdn.com/v4/letter/y/45deac/32.png) [@yaakov.kuperman](https://forum.ansible.com/u/yaakov.kuperman)\
**Post date:** [August 29, 2018, 1:52pm UTC](https://forum.ansible.com/t/variable-concatenation-in-when-statement/28458/1 "2018-08-29T13:52:21Z")

</div>

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?

---

<div class="post-metadata">

**Author:** ![yaakov.kuperman](https://avatars.discourse-cdn.com/v4/letter/y/45deac/32.png) [@yaakov.kuperman](https://forum.ansible.com/u/yaakov.kuperman)\
**Post date:** [August 29, 2018, 1:56pm UTC](https://forum.ansible.com/t/variable-concatenation-in-when-statement/28458/2 "2018-08-29T13:56:45Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![Kai\_Stian\_Olstad](https://avatars.discourse-cdn.com/v4/letter/k/e19adc/32.png) [@Kai\_Stian\_Olstad](https://forum.ansible.com/u/Kai_Stian_Olstad)\
**Post date:** [August 29, 2018, 2:32pm UTC](https://forum.ansible.com/t/variable-concatenation-in-when-statement/28458/3 "2018-08-29T14:32:42Z")

</div>

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

when: "'vmlinuz' ~ kernel\_version not in default\_kernel.stdout"

---

<div class="post-metadata">

**Author:** ![yaakov.kuperman](https://avatars.discourse-cdn.com/v4/letter/y/45deac/32.png) [@yaakov.kuperman](https://forum.ansible.com/u/yaakov.kuperman)\
**Post date:** [August 29, 2018, 3:50pm UTC](https://forum.ansible.com/t/variable-concatenation-in-when-statement/28458/4 "2018-08-29T15:50:49Z")

</div>

definitely cleaner IMO, thanks!
