Access include_vars variables within callback plugin

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”

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” }