# How can I loop over a group of roles

**URL:** <https://forum.ansible.com/t/how-can-i-loop-over-a-group-of-roles/36329>\
**Category:** Ansible Project\
**Created:** [February 13, 2022, 6:32pm UTC](https://forum.ansible.com/t/how-can-i-loop-over-a-group-of-roles/36329 "2022-02-13T18:32:15Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![robert\_rottermann](https://avatars.discourse-cdn.com/v4/letter/r/4bbf92/32.png) [@robert\_rottermann](https://forum.ansible.com/u/robert_rottermann)\
**Post date:** [February 13, 2022, 6:32pm UTC](https://forum.ansible.com/t/how-can-i-loop-over-a-group-of-roles/36329/1 "2022-02-13T18:32:15Z")

</div>

Hi friends in Ansible

I would like to loop over a list roles. The following failing sample should explain what I try to acchieve:

- hosts: all  
become: yes  
become\_method: sudo  
remote\_user: root  
vars:  
servers:
- server1:  
name: abadoc1  
port: 9000
- server2:  
name: abadoc2  
port: 9100
- server3:  
name: abadoc3  
port: 9200

tasks:  
loop: “{{ servers }}”

- include\_role:  
name: common
- include\_role:  
name: dockercompose
- include\_role:  
name: dockerinstallrepos
- include\_role:  
name: logrotate

As you can see, there are a number of servers. For each one a set of roles should executed.

How can I do that? A sample or a link to a tutorial, would be much appreciated.

Thanks a lot for your help

Robert

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/ansible/original/1X/1882d9a01da5d8996a862359b0913cc568a39b84.svg) [@system](https://forum.ansible.com/u/system)\
**Post date:** [February 15, 2022, 9:04pm UTC](https://forum.ansible.com/t/how-can-i-loop-over-a-group-of-roles/36329/2 "2022-02-15T21:04:29Z")

</div>

- hosts: servers  
&nbsp;&nbsp;tasks:  
&nbsp;&nbsp;&nbsp;&nbsp;- import\_role: name=common  
&nbsp;&nbsp;&nbsp;&nbsp;- import\_role: name=dockercompose  
....
