roles/vars/main.yml - but what about other files in this directory

6,015 views
Skip to first unread message

jsch...@juniper.net

unread,
May 21, 2013, 8:31:31 AM5/21/13
to ansible...@googlegroups.com
I'm using roles for template building, and would like to understand the use the of the vars directory a bit more.  From the docs, I see that ansible will automatically pick up roles/{role}/vars/main.yml.  But let's say that I want to put multiple var files in the vars directory.  Is there a way to tell ansible to pickup not only main.yml, but every other *.yml file in that directory as well?

Thank you!

benno joy

unread,
May 21, 2013, 8:48:57 AM5/21/13
to ansible...@googlegroups.com
Could you try this for now

in main.yml
 var_files:
    - "../var1.yml"

Also i guess a feature request has been made for automatic inclusion of all vars file, so down the line this should work without manual inclusion.

- Benno

    
   


On Tue, May 21, 2013 at 6:01 PM, <jsch...@juniper.net> wrote:
I'm using roles for template building, and would like to understand the use the of the vars directory a bit more.  From the docs, I see that ansible will automatically pick up roles/{role}/vars/main.yml.  But let's say that I want to put multiple var files in the vars directory.  Is there a way to tell ansible to pickup not only main.yml, but every other *.yml file in that directory as well?

Thank you!

--
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.
For more options, visit https://groups.google.com/groups/opt_out.
 
 

Michael DeHaan

unread,
May 21, 2013, 8:50:56 AM5/21/13
to ansible...@googlegroups.com
Yep, this was already requested yesterday:

https://github.com/ansible/ansible/issues/2958


--
Michael DeHaan <mic...@ansibleworks.com>
CTO, AnsibleWorks, Inc.
http://www.ansibleworks.com/

jsch...@juniper.net

unread,
May 21, 2013, 9:04:55 AM5/21/13
to ansible...@googlegroups.com
Thank you, but this does not seem to be working.  Are you sure it's "var_files" and not "vars_files"?  I've tried a number of options, with and without quotes around the filename, but no luck.

I do appreciate your help, thank you again!

benno joy

unread,
May 21, 2013, 9:45:37 AM5/21/13
to ansible...@googlegroups.com
Actually i meant vars_files: but i guess even that doesn't seem to work in vars/main.yml, so i guess the only option might be to include it in your main playbook. but i will wait for others to also comment.

Thanks,
Benno 

jsch...@juniper.net

unread,
May 21, 2013, 10:13:42 AM5/21/13
to ansible...@googlegroups.com
Hi Benno,

Thank you for the clarification.  I was thinking (hoping) that "vars_files" would work inside main.yml. 

Do you know when ansible will support reading all .yml files from within the roles/.../vars directory?

Thank you!
-- Jeremy

Michael DeHaan

unread,
May 21, 2013, 10:28:43 AM5/21/13
to ansible...@googlegroups.com
Variable files can't do includes, no.

vars_files is the way to go.

Renaud Guerin

unread,
Jul 2, 2014, 12:10:16 PM7/2/14
to ansible...@googlegroups.com
Hi Michael,

Has this ever been implemented ?

With Vault especially, it seems like a sensible pattern to have a separate encrypted file in vars/ for credentials, next to main.yml

Having to specify include_vars or vars_files explicitly each time feels a little clumsy : shouldn't one reasonably expect a directory named "vars" to have some magic meaning and consider all of its contents automatically (like group_vars and inventory directories do) ?

Since vars/ also doesn't serve as a default path for include_vars in role tasks (AFAIK, you have to explicitly say "../vars/xxx.yml"), technically it might as well be just "roles/x/vars.yml", right ?

Michael DeHaan

unread,
Jul 2, 2014, 6:16:29 PM7/2/14
to ansible...@googlegroups.com
"Has this ever been implemented?"

Vault yes, the feature about multiple files in vars/ automatically being loaded?  No.

Files in vars/ are not all automatically loaded - it would absolutely break certain classes of playbooks, so we can't/won't go there.

include_vars is a good solution from the task file for specific files.




Reply all
Reply to author
Forward
0 new messages