# Ansible Playbook iterating through different variable files

**URL:** <https://forum.ansible.com/t/ansible-playbook-iterating-through-different-variable-files/30919>\
**Category:** Ansible Project\
**Created:** [July 31, 2019, 2:32pm UTC](https://forum.ansible.com/t/ansible-playbook-iterating-through-different-variable-files/30919 "2019-07-31T14:32:28Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![Kristiyan\_Zdravkov](https://avatars.discourse-cdn.com/v4/letter/k/e0b2c6/32.png) [@Kristiyan\_Zdravkov](https://forum.ansible.com/u/Kristiyan_Zdravkov)\
**Post date:** [July 31, 2019, 2:32pm UTC](https://forum.ansible.com/t/ansible-playbook-iterating-through-different-variable-files/30919/1 "2019-07-31T14:32:28Z")

</div>

Hi All,

I am developing a playbook with a health check functionality of an large environment in which there are multiple Applications and Webservers which are Interconnected with each other.  
Each application has already prepared variable file with the all needed information for it. Some of the variables are arrays.

Important thing: the variable names within each of the variable files are identical.

I am pasting the content of two variable files:

##File: pil-az1.yml  
##Content:

> `  
> target\_hosts:
> 
> - server001
> - server002  
> target\_service: jboss7D  
> target\_ws\_service: httpd  
> target\_user: user-as  
> target\_checks:
> - /scripts/checks/health\_pil.sh
> - /scripts/checks/health\_pil2.sh  
> feeding\_servers:
> - serverw001
> - serverw002  
> feeding\_users:
> - user-au  
> feeding\_path: http/chroot/htdocs/mode  
> feeding\_file: status.html  
> app\_dir: jboss  
> Applications: authentication  
> Instance: pilot  
> `
> 
> >

##File: pil-of.yml  
##Content:

---

<div class="post-metadata">

**Author:** ![Kai\_Stian\_Olstad](https://avatars.discourse-cdn.com/v4/letter/k/e19adc/32.png) [@Kai\_Stian\_Olstad](https://forum.ansible.com/u/Kai_Stian_Olstad)\
**Post date:** [August 1, 2019, 6:28am UTC](https://forum.ansible.com/t/ansible-playbook-iterating-through-different-variable-files/30919/2 "2019-08-01T06:28:11Z")

</div>

You would need to include\_vars on one file, do some task(s), and then include the next var and do some task(s) and so on.

With include\_tasks you can loop over a yaml file with one or more tasks in it.

The variable files you can add in a variable that you use in the loop, if you need get the variable dynamicly use the find module.
