Include the correct var file depending on the hostname

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”

group_vars always get loaded for all servers in the group,
include_vars is not meant for group/host_vars