Overriding Role variables using vars_files

1,038 views
Skip to first unread message

Mike Bell

unread,
Sep 7, 2014, 5:42:48 PM9/7/14
to ansible...@googlegroups.com
Hi,

I'm trying to override some default variables in a rolebook that I'm using from ansible galaxy. In my playbook I have the following:

---
- hosts: all
  vars_files
:
   
- "vars/main.yml"
  tasks
:
   
- name: Update apt cache if needed.
      apt
: update_cache=yes cache_valid_time=3600
  roles
:
   
- { role: geerlingguy.apache }


and in my vars/main.yml I have the following:

apache_listen_port: 80
apache_packages
:
 
- apache2


The apache_packages var is defined in the rolebook under /vars

When I run the provision (through vagrant) it still reads the default vars from the role and not my override. I'm still new to ansible but read the documentation on variable inheritance which says this should be possible.

I'm not really sure what I'm doing wrong, any pointers would be greatly appreciated.

Michael DeHaan

unread,
Sep 7, 2014, 6:30:57 PM9/7/14
to ansible...@googlegroups.com
Roles having a defaults/main.yml will have, in that file, variables that are lower priority than basically anything in Ansible - including inventory.

Variables in vars/ are going to be used.

It seems the confusion is the use of "vars/" instead of "defaults/".

(In either case, this is a matter of overriding things - precedence - not OO inheritance)


--
You received this message because you are subscribed to the Google Groups "Ansible Project" group.
To unsubscribe from this group and stop receiving emails from it, send an email to ansible-proje...@googlegroups.com.
To post to this group, send email to ansible...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/ansible-project/e160737b-e671-4d82-8742-951c04500894%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply all
Reply to author
Forward
0 new messages