# struggling with include files

**URL:** <https://forum.ansible.com/t/struggling-with-include-files/21297>\
**Category:** Ansible Project\
**Created:** [April 28, 2016, 12:10pm UTC](https://forum.ansible.com/t/struggling-with-include-files/21297 "2016-04-28T12:10:34Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![Paul\_Davies](https://avatars.discourse-cdn.com/v4/letter/p/e79b87/32.png) [@Paul\_Davies](https://forum.ansible.com/u/Paul_Davies)\
**Post date:** [April 28, 2016, 12:10pm UTC](https://forum.ansible.com/t/struggling-with-include-files/21297/1 "2016-04-28T12:10:34Z")

</div>

I am seriously struggling with trying to include yml files in my top level play

I have prereqcheck.yml in which I want to set the host for the rest of the included files to use

---

<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:** [April 28, 2016, 12:48pm UTC](https://forum.ansible.com/t/struggling-with-include-files/21297/2 "2016-04-28T12:48:14Z")

</div>

So you have 2 types of includes, plays or task lists, you are mixing play level directives in an include inside a play, this is not permitted.

An include inside a play can ONLY have a list of tasks, you are putting vars: and tasks: directives which implies play. In \>=2.0 vars can now be part of any task, so you can put it with the include itself.

- name: Perform all prerequisite checks  
hosts: localhost  
tasks:
- include: prereqcheck\_directories.yml  
vars:

directories:

- directory: “/opt/test”
- directory: “/etc”
- directory: “/xyz”

---

<div class="post-metadata">

**Author:** ![Paul\_Davies](https://avatars.discourse-cdn.com/v4/letter/p/e79b87/32.png) [@Paul\_Davies](https://forum.ansible.com/u/Paul_Davies)\
**Post date:** [April 28, 2016, 3:22pm UTC](https://forum.ansible.com/t/struggling-with-include-files/21297/3 "2016-04-28T15:22:44Z")

</div>

oh man - thank you 🙂

---

<div class="post-metadata">

**Author:** ![Johannes\_Kastl](https://avatars.discourse-cdn.com/v4/letter/j/bbe5ce/32.png) [@Johannes\_Kastl](https://forum.ansible.com/u/Johannes_Kastl)\
**Post date:** [April 28, 2016, 6:24pm UTC](https://forum.ansible.com/t/struggling-with-include-files/21297/4 "2016-04-28T18:24:21Z")

</div>

I wonder that this works, with having the same 'key' called directory  
three times. I am not an expert but I would have guessed this should  
cause all kinds of trouble, because how can you distinguish between  
these three entries?

Johannes

---

<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:** [April 28, 2016, 9:03pm UTC](https://forum.ansible.com/t/struggling-with-include-files/21297/5 "2016-04-28T21:03:49Z")

</div>

its actually a list of dictionaries with single key  
top:

- dictionary: ‘stuff’

top[0][‘dictionary’] == ‘stuff’
