# Referencing fact mid-text in when statement

**URL:** <https://forum.ansible.com/t/referencing-fact-mid-text-in-when-statement/27365>\
**Category:** Ansible Project\
**Created:** [April 24, 2018, 10:02pm UTC](https://forum.ansible.com/t/referencing-fact-mid-text-in-when-statement/27365 "2018-04-24T22:02:29Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![John\_Harmon](https://avatars.discourse-cdn.com/v4/letter/j/edb3f5/32.png) [@John\_Harmon](https://forum.ansible.com/u/John_Harmon)\
**Post date:** [April 24, 2018, 10:02pm UTC](https://forum.ansible.com/t/referencing-fact-mid-text-in-when-statement/27365/1 "2018-04-24T22:02:29Z")

</div>

I have seen other people attempting similar things, but what works for them in their scenarios doesn’t seem to work for me. I am sure it must be a syntax issue. I have a similar when statement, but don’t know how to correctly reference my fact within the string as seen below (tried these two, and various other iterations):

`

- name: Install Spacewalk Repos  
yum:  
name: “{{ item }}”  
state: present  
with\_items:
- first-package-[‘ansible\_distribution\_major\_version’].noarch.rpm
- second-package[ansible\_distribution\_major\_version].noarch.rpm  
`

---

<div class="post-metadata">

**Author:** ![John\_Harmon](https://avatars.discourse-cdn.com/v4/letter/j/edb3f5/32.png) [@John\_Harmon](https://forum.ansible.com/u/John_Harmon)\
**Post date:** [April 24, 2018, 10:12pm UTC](https://forum.ansible.com/t/referencing-fact-mid-text-in-when-statement/27365/2 "2018-04-24T22:12:44Z")

</div>

Figured it out:

`

`

- name: Install Spacewalk Repos  
yum:  
name: “{{ item }}”  
state: present  
with\_items:
- “first-package-{{ ansible\_distribution\_major\_version }}.noarch.rpm”
- “second-package{{ ansible\_distribution\_major\_version }}.noarch.rpm”  
`

`
