Thanks guys for your help, 
I assume you confirm, that there is no such builtin feature in Ansible to 
manage inventory-level templates/files. I'm trying to keep away of doing 
custom things with Ansible like loading variables or files manually, but if 
that would be the only way of progressing, I'll go for your solution. 
One caveat is, that I can't put any files in inventory directory, because 
Ansible tries to interpret them probably as inventory itself and fails with 
errors. I would need to store them on the side of the inventory directory. 
But I would use inventory_dir you @Yannig suggested variable to construct 
the directory name for this (something like {{inventory_dir}}.files or 
similar). 

A bit off-topic I mentioned, was the default *nested* variables. @Jon, what 
I meant is that according to my knowledge it's hard to manage defaults of 
nested variables and override them selectively. Sth like the following: 
My default in the role would be: 

master:
  node1: abc
  node2: def
  node3: ghi

And now I would like to just specify one master.node3 in inventory 
group_vars, without touching the rest, sth like:
master.node3: xyz
# OR
master:
  node3: xyz

This didn't work for me in Ansible. Of course there are workarounds:
1. specify hash_behaviour=merge in ansible.cfg. This is unacceptable for 
me, because ansible.cfg is user specific, external to playbooks. So I can't 
enforce users to put it in their configs.
2. Copy whole defaults even if I want to modify just a single value. This 
solution denies the purpose of defaults.
3. Do advanced yaml hacking, that I'm not yet aware of (using of aliases, 
etc.) 
4. Use jinja2 hash_merge filters to merge the defaults with what user 
provides. Use it in every role as a practice. 

Do you agree with me, that there is no acceptable solution for this problem?

W dniu wtorek, 10 maja 2016 13:12:14 UTC+2 użytkownik Yannig Perre napisał:
>
> Hi,
>
> You can use the magic variable inventory_dir and use it in your playbook. 
> Here's the default value:
>
> ansible -m debug -a var=inventory_dir localhost 
> localhost | SUCCESS => { 
>    "inventory_dir": "/etc/ansible" 
> }
>
> Regards,
>
> Yannig
>
> Le lundi 9 mai 2016 11:13:31 UTC+2, Krzysztof Zarzycki a écrit :
>>
>> Hi! 
>> Is it possible to store files or templates per inventory? Similar to how 
>> we can store group_vars per inventory.
>> I often hit the issue with Ansible, that I would like to store a file or 
>> a template per inventory (TEST, PROD). These usually are large 
>> configuration files of some components (like Hadoop), that are almost 
>> completely different per inventory and have so many variables, that it 
>> seems worthless to create shell-like templates with a lot of variables in 
>> it. Especially, that these configuration files are nicely written, with a 
>> lot of nested structure, while ansible variables are just flat (IMHO using 
>> nested variables in Ansible is unfeasible either because it's hard to do 
>> defaults and overrides, hard to do references between variables, etc).   
>>
>> Not only templates, I would also like to store binary files (zipfiles?) 
>> that could be different per inventory. Is that possible? 
>>
>> Thanks a lot for answers,
>> Krzysztof 
>>
>>

-- 
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 [email protected].
To post to this group, send email to [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/ansible-project/d3fe3664-62ca-44f5-aaaa-60320e688b29%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to