# Include the correct var file depending on the hostname

**URL:** <https://forum.ansible.com/t/include-the-correct-var-file-depending-on-the-hostname/19422>\
**Category:** Ansible Project\
**Created:** [October 2, 2015, 5:41pm UTC](https://forum.ansible.com/t/include-the-correct-var-file-depending-on-the-hostname/19422 "2015-10-02T17:41:14Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![Sam\_S](https://avatars.discourse-cdn.com/v4/letter/s/edb3f5/32.png) [@Sam\_S](https://forum.ansible.com/u/Sam_S)\
**Post date:** [October 2, 2015, 5:41pm UTC](https://forum.ansible.com/t/include-the-correct-var-file-depending-on-the-hostname/19422/1 "2015-10-02T17:41:14Z")

</div>

I have three sets of servers. Depending on the hostname, I want the client to grab the correct file. I tested the playbook on a server with the word “batch” but it picks up both files (group\_vars/perl and group\_vars/perl).

pre\_tasks:

- include\_vars: group\_vars/web  
when: “‘web’ in ansible\_hostname”
- include\_vars: group\_vars/batch  
when: “‘web’ not in ansible\_hostname”
- include\_vars: group\_vars/perl  
when: “‘web’ not in ansible\_hostname” or “‘batch’ not in ansible\_hostname”

---

<div class="post-metadata">

**Author:** ![Brian\_Coca](https://avatars.discourse-cdn.com/v4/letter/b/6de8d8/32.png) [@Brian\_Coca](https://forum.ansible.com/u/Brian_Coca)\
**Post date:** [October 2, 2015, 7:03pm UTC](https://forum.ansible.com/t/include-the-correct-var-file-depending-on-the-hostname/19422/2 "2015-10-02T19:03:40Z")

</div>

group\_vars always get loaded for all servers in the group,  
include\_vars is not meant for group/host\_vars
