# Roles list variable

**URL:** <https://forum.ansible.com/t/roles-list-variable/13919>\
**Category:** Ansible Project\
**Created:** [November 16, 2013, 4:06pm UTC](https://forum.ansible.com/t/roles-list-variable/13919 "2013-11-16T16:06:16Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![Marc\_Trudel](https://avatars.discourse-cdn.com/v4/letter/m/f1d935/32.png) [@Marc\_Trudel](https://forum.ansible.com/u/Marc_Trudel)\
**Post date:** [November 16, 2013, 4:06pm UTC](https://forum.ansible.com/t/roles-list-variable/13919/1 "2013-11-16T16:06:16Z")

</div>

Hi,

For one of the playbook I am trying to write, I am trying to allow the input of a dynamic role list.

However, this does not seem to work:

- name: “Apply extra roles (see .myfile.yml)”  
hosts: all  
gather\_facts: true  
sudo: true  
user: vagrant  
roles: extra\_roles

Does it make sense? Is it supported? Or should I try to do this differently?

---

<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:** [November 16, 2013, 6:10pm UTC](https://forum.ansible.com/t/roles-list-variable/13919/2 "2013-11-16T18:10:56Z")

</div>

I’m not sure where you expect “.myfile.yml” to be loaded.

Can you elaborate?

---

<div class="post-metadata">

**Author:** ![Marc\_Trudel](https://avatars.discourse-cdn.com/v4/letter/m/f1d935/32.png) [@Marc\_Trudel](https://forum.ansible.com/u/Marc_Trudel)\
**Post date:** [November 17, 2013, 7:32am UTC](https://forum.ansible.com/t/roles-list-variable/13919/3 "2013-11-17T07:32:53Z")

</div>

Its a bit tricky to explain… at any rate, my question really is about using a variable as a role list. Is this doable/logical/stupid?

---

<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:** [November 17, 2013, 6:40pm UTC](https://forum.ansible.com/t/roles-list-variable/13919/4 "2013-11-17T18:40:21Z")

</div>

You can achieve this something like this if you … really … want to.

- hosts: all  
tasks:

- group\_by: key=should-foo-{{ ‘foo’ in my\_roles }}

- group\_by: key=should-bar-{{ ‘bar’ in my\_roles }}

- hosts: should-foo-True  
roles:

- foo

- hosts: should-bar-True  
roles:

- bar

Otherwise you can’t because plays affect all hosts and the variables for different hosts would be different.

It’s better to leave playbooks as the concept that map hosts to roles and keep it simple.

---

<div class="post-metadata">

**Author:** ![Evan\_Kaufman](https://avatars.discourse-cdn.com/v4/letter/e/e99b99/32.png) [@Evan\_Kaufman](https://forum.ansible.com/u/Evan_Kaufman)\
**Post date:** [July 26, 2014, 6:09pm UTC](https://forum.ansible.com/t/roles-list-variable/13919/5 "2014-07-26T18:09:37Z")

</div>

I’m trying to accomplish something similar, where I’d have a list of roles defined in the **group\_vars/all** file (where I’d disable certain roles by just commenting them out):

`

---

<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:** [July 26, 2014, 7:57pm UTC](https://forum.ansible.com/t/roles-list-variable/13919/6 "2014-07-26T19:57:10Z")

</div>

Roles must be a list, but the value of roles is not templated.

It expects this to be in the playbook.

It wouldn’t work with inventory variables anyway, so there’s not much point.

Inventory variables happen after tasks start getting parsed.

---

<div class="post-metadata">

**Author:** ![Mouncif\_Benziane](https://avatars.discourse-cdn.com/v4/letter/m/ec9cab/32.png) [@Mouncif\_Benziane](https://forum.ansible.com/u/Mouncif_Benziane)\
**Post date:** [June 15, 2017, 11:01pm UTC](https://forum.ansible.com/t/roles-list-variable/13919/7 "2017-06-15T23:01:14Z")

</div>

Any solutions for this? I am trying to do the same but no luck!
