I’ve been playing around with paramaterized playbook includes, and I think I have discovered a bug, but perhaps it is expected behavior, so I thought I would ask.
The short version is that parameters do not override data from vars_files. I presume this is not the expected behavior? I didn’t have any luck finding documentation that would tell me for sure either way.
I’ve only tested on 1.9.0.1, so it is possible that it is fixed in dev, but I’ve not had a change to test that.
Now with much more detail…
Let’s say you have play.yml with the following:
hosts: all
include: include.yml parameter=passed
And then you have include.yml:
hosts: all
vars:
parameter: vars
tasks:
debug:
msg: parameter={{ parameter }}
This results in what to me is the expected result (the parameter overrides the value from ‘vars’:
I attempted to try this with the current devel branch from github and my examples don’t work at all. There seem to be major differences and thus I can’t really test properly if this issue still exists.
This leaves me with three questions:
Is there something horribly wrong with the way I’ve written my example playbooks?
Is it expected that parameters passed to included playbooks will be replace by values in the vars_files defined in the included playbook?
If so this breaks the way I was planning on handling differences for different operating systems.
I am planning on working more with ansible, but I’m sort of stalled out right now as I don’t want to do things in a horribly broken way of based on a behavior that might actually be a bug. Any feedback is appreciated.
Ansible doesn't through an error if you specify the include at the same
level as name/hosts/etc... but it seem to produce an unexpected behavior
(the contents of the current playbook are completed replaced).
also vars_files shouldnt have precendce over vars in an include, are you testing this in v2 ? can you please checkout the latest devel version and check.
Ok, so I have things in a format that run under 1.9 as well as v2/current devel and the behavior is very odd. I’ve put together some sample playbook files to help demonstrate the behavior I am seeing:
The comments in that file describing the behavior all apply to v2/current devel. To summarize the comments, basically variable layering appears to be very much broken in v2, but how it breaks seems highly variable (but reproducible).
For version 1.9, the behavior is broken, but as far as I know right now it is always broken in the same way. That is vars_files always override parameters. But to be honest, I’ve mainly focused on testing against v2.