# Looping from a list of definitions and values which is based on group var

**URL:** <https://forum.ansible.com/t/looping-from-a-list-of-definitions-and-values-which-is-based-on-group-var/24513>\
**Category:** Ansible Project\
**Created:** [May 18, 2017, 2:31pm UTC](https://forum.ansible.com/t/looping-from-a-list-of-definitions-and-values-which-is-based-on-group-var/24513 "2017-05-18T14:31:13Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![Ilan\_Harel](https://avatars.discourse-cdn.com/v4/letter/i/b487fb/32.png) [@Ilan\_Harel](https://forum.ansible.com/u/Ilan_Harel)\
**Post date:** [May 18, 2017, 2:31pm UTC](https://forum.ansible.com/t/looping-from-a-list-of-definitions-and-values-which-is-based-on-group-var/24513/1 "2017-05-18T14:31:13Z")

</div>

Might be a simple solution that I didn’t understand after reading [http://docs.ansible.com/ansible/playbooks\_loops.html](http://docs.ansible.com/ansible/playbooks_loops.html) but here is my case:

There is a command that should run different parameters for the same role based on group of hosts for example:

webservers group:  
/usr/bin/command definition1=value1a  
/usr/bin/command definition2=value2a  
/usr/bin/command definition3=value3a

dbservers group:  
/usr/bin/command definition1=value1b  
/usr/bin/command definition2=value2b  
/usr/bin/command definition3=value3b  
/usr/bin/command definition4=value4b

There will be two var files, webserver.yml and dbservers.yml with the following content:  
webserver.yml  
definition1,value1a  
definition2,value2a  
definition3,value3a

dbservers.yml  
definition1,value1b  
definition2,value2b  
definition3,value3b  
definition4,value4b

1. how should I loop through all pairs of definitions and values in var files and run the command?
2. where do I add the name definition that it will be displayed when it’s running?

Thanks in advance
