# variable expansion in includes

**URL:** <https://forum.ansible.com/t/variable-expansion-in-includes/13107>\
**Category:** Ansible Project\
**Created:** [July 12, 2013, 1:09am UTC](https://forum.ansible.com/t/variable-expansion-in-includes/13107 "2013-07-12T01:09:21Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![Ed\_Zarecor](https://avatars.discourse-cdn.com/v4/letter/e/b487fb/32.png) [@Ed\_Zarecor](https://forum.ansible.com/u/Ed_Zarecor)\
**Post date:** [July 12, 2013, 1:09am UTC](https://forum.ansible.com/t/variable-expansion-in-includes/13107/1 "2013-07-12T01:09:21Z")

</div>

Is it possible to do something like the following:

- include: os/${ansible\_distribution}.yml

As so, it’s not working, but I’m hoping there’s a way to accomplish something like this.

Best,

Ed.

---

<div class="post-metadata">

**Author:** ![Michael\_DeHaan](https://avatars.discourse-cdn.com/v4/letter/m/c4cdca/32.png) [@Michael\_DeHaan](https://forum.ansible.com/u/Michael_DeHaan)\
**Post date:** [July 12, 2013, 3:13am UTC](https://forum.ansible.com/t/variable-expansion-in-includes/13107/2 "2013-07-12T03:13:00Z")

</div>

No, it’s not, because tasks must apply uniformly across all hosts in a play.

Also I should point out that Ansible 1.2 and later strongly prefers {{ variable }} for variable replacement.

---

<div class="post-metadata">

**Author:** ![C\_Morgan\_Hamill](https://avatars.discourse-cdn.com/v4/letter/c/ebca7d/32.png) [@C\_Morgan\_Hamill](https://forum.ansible.com/u/C_Morgan_Hamill)\
**Post date:** [July 12, 2013, 2:08pm UTC](https://forum.ansible.com/t/variable-expansion-in-includes/13107/3 "2013-07-12T14:08:07Z")

</div>

Excerpts from Michael DeHaan's message of 2013-07-11 23:13:00 -0400:

> No, it's not, because tasks must apply uniformly across all hosts in a play.

Something like this would work, though, no?

&nbsp;&nbsp;&nbsp;&nbsp;- include: centos.yaml  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;when: ansible\_distribution == 'CentOS'

&nbsp;&nbsp;&nbsp;&nbsp;- include: debian.yaml  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;when: ansible\_distribution == 'Debian'

---

<div class="post-metadata">

**Author:** ![Michael\_DeHaan2](https://avatars.discourse-cdn.com/v4/letter/m/da6949/32.png) [@Michael\_DeHaan2](https://forum.ansible.com/u/Michael_DeHaan2)\
**Post date:** [July 12, 2013, 2:13pm UTC](https://forum.ansible.com/t/variable-expansion-in-includes/13107/4 "2013-07-12T14:13:11Z")

</div>

Yes, indeed.

What this does is affix the “when” statement to each task included, anding it with any other when statements, if neccessary.

You can also attach a when to a role.
