# which is a correct way to reuse code from roles?

**URL:** <https://forum.ansible.com/t/which-is-a-correct-way-to-reuse-code-from-roles/16408>\
**Category:** Ansible Project\
**Tags:** ansible-project\
**Created:** [October 2, 2014, 6:55pm UTC](https://forum.ansible.com/t/which-is-a-correct-way-to-reuse-code-from-roles/16408 "2014-10-02T18:55:35Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![Michael\_Wozniak](https://avatars.discourse-cdn.com/v4/letter/m/f1d935/32.png) [@Michael\_Wozniak](https://forum.ansible.com/u/Michael_Wozniak)\
**Post date:** [October 2, 2014, 6:55pm UTC](https://forum.ansible.com/t/which-is-a-correct-way-to-reuse-code-from-roles/16408/1 "2014-10-02T18:55:35Z")

</div>

Does this work:

- include: …/…/includes\_common/pkg\_from\_repo.yaml  
with\_items:
- { name: ‘bash’ }
- { name: ‘bash-completion’ }
- { name: ‘screen’ }

etc…

---

<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:** [October 2, 2014, 8:57pm UTC](https://forum.ansible.com/t/which-is-a-correct-way-to-reuse-code-from-roles/16408/2 "2014-10-02T20:57:32Z")

</div>

One cannot add a with\_items to an include.

I think I’ve discussed not doing the “package abstraction thing” in another thread, and why it would be better to just list the packages per os, like

- yum: name={{ item }} state=installed  
with\_items: yum\_packages  
when: ansible\_os\_family == ‘RedHat’

etc
