Include the correct var file depending on the hostname

27 views
Skip to first unread message

Samnang Sen

unread,
Oct 2, 2015, 1:41:15 PM10/2/15
to Ansible Project
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"

Brian Coca

unread,
Oct 2, 2015, 3:03:49 PM10/2/15
to Ansible Project
group_vars always get loaded for all servers in the group,
include_vars is not meant for group/host_vars

--
Brian Coca
Reply all
Reply to author
Forward
0 new messages