# include: and variables (changed in 1.8?)

**URL:** <https://forum.ansible.com/t/include-and-variables-changed-in-1-8/16954>\
**Category:** Ansible Project\
**Created:** [December 3, 2014, 9:31pm UTC](https://forum.ansible.com/t/include-and-variables-changed-in-1-8/16954 "2014-12-03T21:31:39Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![Ross\_Becker](https://avatars.discourse-cdn.com/v4/letter/r/ed8c4c/32.png) [@Ross\_Becker](https://forum.ansible.com/u/Ross_Becker)\
**Post date:** [December 3, 2014, 9:31pm UTC](https://forum.ansible.com/t/include-and-variables-changed-in-1-8/16954/1 "2014-12-03T21:31:39Z")

</div>

So, I have a batch of playbooks that include tasks where the filenames are determined by variables;

- include: tasks/mytask-{{onevar}}-{{anothervar}}.yml

This was working up through ansible 1.7.2. As of ansible 1.8.0 (and also tested on ansible 1.8.1) this stopped working; the variables are no longer interpreted, and ansible exits complaining with a message:

1. ERROR: file could not read: /root/work/playbooks/tasks/bar-{{platform}}.yml

Below are the bits to reproduce:

1. foo.yml:

2. 
  - hosts: slave

3. user: root

4. 
5. vars:

6. platform: rpm

7. 
8. tasks:

9. 
  - include: “tasks/bar-{{platform}}.yml”

10. 
11. tasks/bar-rpm.yml:

12. 
  - name: install OS package dependencies

13. action: yum pkg={{item}} state=installed

14. with\_items:

15. 
  - wget

16. 
  - ntpdate

17. 
18. 
19. hosts.inv:

20. [slave]

21. sc-cluster-20-04

22. sc-cluster-20-05

23. sc-cluster-20-06

The above case works on all ansible versions up through 1.7.2, and breaks on 1.8.0+. I searched on here a bit regarding this, and found the suggestion that variables as part of include filenames would only work if passed in as extra vars, as only those would be resolvable early enough. I tested that on 1.7.2 by taking out the “vars:” section and passing the value in as an extra var on the command-line. That test worked on 1.7.2 and earlier, but does not work in 1.8.0+.

Is there any means where this functionality should actually work in 1.8.x?

---

<div class="post-metadata">

**Author:** ![Brian\_Coca](https://avatars.discourse-cdn.com/v4/letter/b/6de8d8/32.png) [@Brian\_Coca](https://forum.ansible.com/u/Brian_Coca)\
**Post date:** [December 3, 2014, 9:38pm UTC](https://forum.ansible.com/t/include-and-variables-changed-in-1-8/16954/2 "2014-12-03T21:38:45Z")

</div>

a few bugs with variables were present in 1.8.x, could you test with  
current devel as there are fixes there (soon to be released) that  
might solve your issue.

---

<div class="post-metadata">

**Author:** ![Ross\_Becker](https://avatars.discourse-cdn.com/v4/letter/r/ed8c4c/32.png) [@Ross\_Becker](https://forum.ansible.com/u/Ross_Becker)\
**Post date:** [December 3, 2014, 9:49pm UTC](https://forum.ansible.com/t/include-and-variables-changed-in-1-8/16954/3 "2014-12-03T21:49:36Z")

</div>

Ahah- yes, it works again when I tested ansible at current git state. OK, I’ll make sure that we’re pegging our ansible version to 1.7.2 for the moment, and wait for the next release to pull that back out. Thanks!

---

<div class="post-metadata">

**Author:** ![Michael\_DeHaan1](https://avatars.discourse-cdn.com/v4/letter/m/5e9695/32.png) [@Michael\_DeHaan1](https://forum.ansible.com/u/Michael_DeHaan1)\
**Post date:** [December 3, 2014, 9:49pm UTC](https://forum.ansible.com/t/include-and-variables-changed-in-1-8/16954/4 "2014-12-03T21:49:39Z")

</div>

Also I’d double check that those two vars in the include do not come from facts or inventory.

(That would have been any any-version thing)

---

<div class="post-metadata">

**Author:** ![Ross\_Becker](https://avatars.discourse-cdn.com/v4/letter/r/ed8c4c/32.png) [@Ross\_Becker](https://forum.ansible.com/u/Ross_Becker)\
**Post date:** [December 3, 2014, 10:43pm UTC](https://forum.ansible.com/t/include-and-variables-changed-in-1-8/16954/5 "2014-12-03T22:43:34Z")

</div>

Funny enough, in prior versions and in dev branch, having those facts come in via a “vars:” statement in the playbook works. Most places they’re being used, they come in via extra-vars, and it wouldn’t have been a big deal to change this instance to match that, but not working at all would’ve been a big deal.

---

<div class="post-metadata">

**Author:** ![alicia](https://avatars.discourse-cdn.com/v4/letter/a/ecd19e/32.png) [@alicia](https://forum.ansible.com/u/alicia)\
**Post date:** [March 4, 2016, 5:46pm UTC](https://forum.ansible.com/t/include-and-variables-changed-in-1-8/16954/6 "2016-03-04T17:46:16Z")

</div>

I’m trying to use a task where the filenames are determined by variables, running into what looks like the same issue, and wondering how best to accomplish what I want to do. I’m using Ansible 1.9.1.

Within a role, I have two task files for installing two versions of the same component that install in different ways.

In the role’s defaults, I have two variables: component\_version and component\_main\_version.  
The component\_main\_version variable is defined in the defaults/main.yml this way:  
component\_main\_version: “{{ component\_version[0:1] }}”  
My intention is to pull the main version number (e.g. 4) from the full version number (e.g. 4.8.1).

In tasks/main.yml, I have - include: component\_{{ component\_main\_version }}.yml.  
When I run my playbook I get  
ERROR: file could not read: /path/to/role/tasks/component\_{{ component\_main\_version }}.yml  
If I pass the variable at the command line:  
-e component\_main\_version=4  
I get the desired behavior.

Am I defining the derived variable incorrectly? Am I running up against the bug described here? Is there a better way to accomplish what I’m trying to do?

Any insight/help greatly appreciated.  
Thanks,  
Alicia
