# Including mulitple files

**URL:** <https://forum.ansible.com/t/including-mulitple-files/15971>\
**Category:** Ansible Project\
**Created:** [August 17, 2014, 9:32am UTC](https://forum.ansible.com/t/including-mulitple-files/15971 "2014-08-17T09:32:33Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![Akos\_Vandra](https://avatars.discourse-cdn.com/v4/letter/a/8baadc/32.png) [@Akos\_Vandra](https://forum.ansible.com/u/Akos_Vandra)\
**Post date:** [August 17, 2014, 9:32am UTC](https://forum.ansible.com/t/including-mulitple-files/15971/1 "2014-08-17T09:32:33Z")

</div>

Hello!

I’m struggling with importing the functionality of deploy\_revision from chef to ansible.

In case of ruby this means the following steps:

- checkout git repo to /revisions/sha1
- run bundle install in there
- create necessary custom configuration files
- take any necessary custom steps to configure the installation
- update symlink of /current to point to /revisions/sha1

Now what I’d like to do is to put steps 1,2,5 into a separate task file, and use it like this:

- include: …/…/common/tasks/ruby-git-deploy.yml  
deploy\_dir: /opt/water/revisions  
deploy\_revision: master  
deploy\_repository: [git@github.com](mailto:git@github.com)/…

tasks\_before\_symlink:

- roles/water-meter/setup.yml
- roles/common/rake\_db\_migrate.yml

the tasks\_before\_symlink would point to the tasks files that would carry out steps 3,4, but I seem to be unable to include them:

- include: ‘{{item}}’  
with\_items: {{ tasks\_before\_symlink }}

complains about deprecated code:

ERROR: [DEPRECATED]: include + with\_items is a removed deprecated feature (in /Users/avandra/projects/freelancer/liveoaksys/water-playbook/roles/common/tasks/ruby-git-deploy.yml). Please update your playbooks.

There is no realy pointer on what is the “new way” to do this, can you help me out?

Regards,  
Akos Vandra

---

<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:** [August 17, 2014, 1:05pm UTC](https://forum.ansible.com/t/including-mulitple-files/15971/2 "2014-08-17T13:05:03Z")

</div>

There are various approaches to this, but here’s an example role that does this:

[https://github.com/f500/ansible-project\_deploy](https://github.com/f500/ansible-project_deploy)

We’re talking about making a helper module in Ansible 1.8 timeframe that would make a lot of this easier without needing a custom role.

While you cannot use “include” together with a “with\_items”, you can pass a list to a role, and then loop inside the role on each task.

- { role: name: ‘foo’, stuff: a\_list }

# in tasks file:

- shell: echo parameter is {{ item }}  
with\_items: a\_list

Etc

---

<div class="post-metadata">

**Author:** ![Kim\_Ausloos](https://avatars.discourse-cdn.com/v4/letter/k/8baadc/32.png) [@Kim\_Ausloos](https://forum.ansible.com/u/Kim_Ausloos)\
**Post date:** [August 18, 2014, 11:44am UTC](https://forum.ansible.com/t/including-mulitple-files/15971/3 "2014-08-18T11:44:15Z")

</div>

Hi Michael,

Is there a github issue for the module proposal you are talking about? I have multiple use cases for includes with\_fileglob ( for example [https://gist.github.com/anonymous/1691f3ab625175011449](https://gist.github.com/anonymous/1691f3ab625175011449) ) and the current proposal feel kind of hackish. It could, of course, be me because I’m not using ansible professionally…

Thanks!  
Kim

---

<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:** [August 18, 2014, 12:26pm UTC](https://forum.ansible.com/t/including-mulitple-files/15971/4 "2014-08-18T12:26:39Z")

</div>

There’s not a github issue.

Generally we don’t want to see feature request tickets (GitHub ticket organization is a giant pain – though we’ll leave them open when someone has a especially good idea), so it’s mostly a matter of getting the work done. We’ve got a note to look at this in 1.8 timeframe.

---

<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:** [August 18, 2014, 12:27pm UTC](https://forum.ansible.com/t/including-mulitple-files/15971/5 "2014-08-18T12:27:18Z")

</div>

“and the current proposal feel kind of hackish”

A matter of opinion, clearly, which I don’t think is fair to those discussing it unless you can present a better proposal.

In any event, group discussion should happen on ansible-devel, not on GitHub.

---

<div class="post-metadata">

**Author:** ![Akos\_Vandra](https://avatars.discourse-cdn.com/v4/letter/a/8baadc/32.png) [@Akos\_Vandra](https://forum.ansible.com/u/Akos_Vandra)\
**Post date:** [August 18, 2014, 12:42pm UTC](https://forum.ansible.com/t/including-mulitple-files/15971/6 "2014-08-18T12:42:14Z")

</div>

I have solved my issue by providing a variable to the deploy task,  
which will in turn include that.  
But it does feel somewhat like writing try-catch-finally behaviour  
code in C, having to split all the before, between and after stuff  
into separate files (functions).

includes: git-deploy.yml  
vars:  
&nbsp;&nbsp;before\_migrate\_tasks: my-hook.yml

@@@ git-deploy.yml

- prepare\_tasks  
- include: {{ before\_migrate\_tasks }}  
- migrate\_tasks

---

<div class="post-metadata">

**Author:** ![Kim\_Ausloos](https://avatars.discourse-cdn.com/v4/letter/k/8baadc/32.png) [@Kim\_Ausloos](https://forum.ansible.com/u/Kim_Ausloos)\
**Post date:** [August 18, 2014, 12:53pm UTC](https://forum.ansible.com/t/including-mulitple-files/15971/7 "2014-08-18T12:53:54Z")

</div>

Hi Michael,

I was talking about the looping of each task in a role, not about any new proposal or old functionality, excuse me for any misunderstanding. I also wasn’t aware about ansible-development group, thank you for pointing that out.
