# Access include\_vars variables within callback plugin

**URL:** <https://forum.ansible.com/t/access-include-vars-variables-within-callback-plugin/19911>\
**Category:** Ansible Developer\
**Created:** [December 1, 2015, 8:27pm UTC](https://forum.ansible.com/t/access-include-vars-variables-within-callback-plugin/19911 "2015-12-01T20:27:10Z")\
**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:** [December 1, 2015, 8:27pm UTC](https://forum.ansible.com/t/access-include-vars-variables-within-callback-plugin/19911/1 "2015-12-01T20:27:10Z")

</div>

I can access all vars within group\_vars by using the following code.

`  
host\_vars = self.playbook.inventory.get\_variables(hosts[0])

`

However, my playbook is based on the server name, so it loads the correct variable file. How can I access the variable within the file that it loads? I have a variable called “rpm\_modules” and the values are different per host group. Maybe there’s a better way of handling this via group\_vars?

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

---

<div class="post-metadata">

**Author:** ![igorc](https://sea1.discourse-cdn.com/ansible/user_avatar/forum.ansible.com/igorc/32/5491_2.png) [@igorc](https://forum.ansible.com/u/igorc)\
**Post date:** [December 3, 2015, 12:11am UTC](https://forum.ansible.com/t/access-include-vars-variables-within-callback-plugin/19911/2 "2015-12-03T00:11:16Z")

</div>

Isn’t it better to reorganize this with roles? Each role will have separate rpm\_modules var in the roles/rolename/vars/main.yml and you can choose which role to apply to each host based on some logic.

- { role: web, when: “‘web’ in ansible\_hostname” }
