Sorry, the variables "node1","node2", "node3" or "master" were just example variables, unfortunate names. I just meant some children variables of some master variable.
W dniu środa, 11 maja 2016 07:44:05 UTC+2 użytkownik J Hawkesworth napisał: > > Not sure I fully understand what you are trying to achieve so I may have > the wrong idea here. > > It maybe that you have just used node1, node2, node3 as example variable > names, but if you are referring to machines you can refer to variables, > including nested ones for other hosts in other groups inside your playbook > - have a look at > > > http://docs.ansible.com/ansible/faq.html#how-do-i-access-a-variable-of-the-first-host-in-a-group > > If I have a var which I can't set declaratively in defaults or host/group > vars I would calculate it using set_fact at runtime in my playbook. > > Hope this helps, > > Jon > > On Tuesday, May 10, 2016 at 7:25:04 PM UTC+1, Krzysztof Zarzycki wrote: >> >> 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/8ae20540-d4bd-47c2-8d60-6dabcbd289f8%40googlegroups.com. For more options, visit https://groups.google.com/d/optout.
