> On 2015-12-13, at 01:07, Igor Cicimov <[email protected]> wrote: > > Well of course they get overwritten in the *same* play since all variables > are *global* during the play execution,
Well, until yesterday I wouldn't say "of course". If I used host variables, then I would understand this as being "of course". I thought that group variables are applied to the group's host(s) upon processing. In the sense that if I don't process the other group, the variables would remain intact. But then, after writing the previous post, I dumped the 'hostvars' and only then realised what's going on. > otherwise if you call group1 after group0 what will happen is group1 will get > the variables from group0, which is not desirable, right? Frankly - I would expect/desire that when I call group0, I get variables defined for group0, when I call group1, I get the values as defined for group1. Even if they apply to the same host in the end. And if I wanted them within the host scope, I would use host_vars rather then group_vars. I understand that this is somewhat more difficult to implement, because a kind of "group context" or "group scope" would need to be introduced to the Ansible's inner workings. From what I saw in the variables dump, nothing like that's been done so far. Seems like during play execution, everything's thrown into one basket (becomes global as you mentioned). This is surely easier to implement but in this case I find the group_vars concept of noticeably lower value and also susceptible to errors, unless one understands that they are actually kind of "global host_vars". > What you need to do is rethink your playbooks and inventory structure, think > of using multiple roles instead of single one with many tasks The setup is quite complex with many roles and even those roles have number of tasks, many of them being very similar, which is why tried to extract the repetitive tasks from within the roles and place those in the upper level, where it would be accessible for all roles. You know, the good, old DRY stuff.. "Of course" I used the same variable names in all the roles as they do the same thing and the shared, included tasks use them this way. Things - kind of - worked until I started including tasks, which is probably where it traverses the directory structure and overwrites the values. > and keep the global variables names unique if you don't want them overwritten. Actually - as I wrote above - I didn't expect them to be global. I wanted to keep them within the scope of role/group. Both approaches fail due to variables being overwritten. I spent several days on this already and eventually ended up generating different role/group variable naming (prefixes). Then I assign them (set_fact:) to the required variables right before including the tasks from upper level. Reworked half of the setup this way - works so far but I don't find it an elegant way. I've got this feeling like I am writing a program with tens of thousands lines of code and am allowed to use only global variables everywhere... > > On Sunday, December 13, 2015 at 3:31:17 AM UTC+11, silverdr wrote: > I /think/ I know where the problem comes from: I encountered it with group > vars defined in the inventory file. I eventually moved both the role > variables and group_vars into inventory file, trying to establish one place > where the variables are defined. Now: > My inventory file looks like this (IPs are dummy): > > [group0] > 234.123.41.44 > [group0:vars] > var0=00 > var1=01 > > [group1] > 234.123.41.45 > [group1:vars] > var0=10 > var1=11 > > Now, in this configuration, variables have their values intact. But when I > refer with both groups to the same host, like: > > [group0] > 234.123.41.44 > [group0:vars] > var0=00 > var1=01 > > [group1] > 234.123.41.44 > [group1:vars] > var0=10 > var1=11 > > which I guess is rather typical when deploying to development environment, > then the group0 variables get overwritten! > > Since my configuration with "defaults" has been applied to similar inventory, > my best guess is that this caused the problem there too. Now - what to do in > order to have the variables keep their values for different groups, even if > the host happens to be the same? And shouldn't it be the case anyway? > > -- > You received this message because you are subscribed to a topic in the Google > Groups "Ansible Project" group. > To unsubscribe from this topic, visit > https://groups.google.com/d/topic/ansible-project/gWN-uuj7NRI/unsubscribe. > To unsubscribe from this group and all its topics, 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/c74dc634-04fc-4380-8800-99b5978e649d%40googlegroups.com. > For more options, visit https://groups.google.com/d/optout. -- 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/B124868B-7588-42AB-8A37-ACF3C3DE1953%40srebrnysen.com. For more options, visit https://groups.google.com/d/optout.
