Ansible vars precendence

17 views
Skip to first unread message

Pranay Nanda

unread,
May 27, 2018, 2:33:22 PM5/27/18
to Ansible Project
I have an Ansible playbook that I want to load custom variables for. I do not have access to the inventory but I wish to classify the variables by their host names which can be classified in groups. The jobs would be fired from Ansible Tower. Where should I put these variables such that they by default override the values in tower? I've tried putting them in the vars file in the role that's supposed to run but the operation occurs as per the values in tower. I've tried putting them in the main play as well but it returns an error "<<vars file>> should be a list or None."

-  name: manage services
   hosts: all
   tasks:
   include_vars:
     - "{{playbook_dir}}/../roles/service_management/vars/s1s2grouping.yml"

A little test in the role shows that the file is being loaded.


- name: include variables
  include_vars:
    file: s1s2grouping.yml
  register: checking

- debug: "msg={{checking.ansible_included_var_files}}"

The above code results in a positive answer.

Pranay Nanda

unread,
May 27, 2018, 2:52:20 PM5/27/18
to Ansible Project
I fixed the error in the main play

-  name: manage services
   hosts: all
   tasks:
     - include_vars: "{{playbook_dir}}/../roles/service_management/vars/s1s2grouping.yml"

But now it won't read variables
Reply all
Reply to author
Forward
0 new messages