# parameterize include question / possible bug

**URL:** <https://forum.ansible.com/t/parameterize-include-question-possible-bug/18427>\
**Category:** Ansible Project\
**Created:** [June 8, 2015, 9:02am UTC](https://forum.ansible.com/t/parameterize-include-question-possible-bug/18427 "2015-06-08T09:02:36Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![Michael\_Johnson1](https://avatars.discourse-cdn.com/v4/letter/m/dec6dc/32.png) [@Michael\_Johnson1](https://forum.ansible.com/u/Michael_Johnson1)\
**Post date:** [June 8, 2015, 9:02am UTC](https://forum.ansible.com/t/parameterize-include-question-possible-bug/18427/1 "2015-06-08T09:02:36Z")

</div>

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’:

ok: [[sun.apomorph.com](http://sun.apomorph.com)] =\> {

“msg”: “parameter=passed”

}

However, if you create vars.yml with the following:

parameter: file

And then change include.yml to contain the following:

- hosts: all

vars:

parameter: vars

vars\_files:

- vars.yml

tasks:

- debug:

msg: parameter={{ parameter }}

The result is not what I would expect (the value from vars\_file is utilized:

TASK: [debug] \*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*

ok: [[sun.apomorph.com](http://sun.apomorph.com)] =\> {

“msg”: “parameter=file”

}

---

<div class="post-metadata">

**Author:** ![Michael\_Johnson1](https://avatars.discourse-cdn.com/v4/letter/m/dec6dc/32.png) [@Michael\_Johnson1](https://forum.ansible.com/u/Michael_Johnson1)\
**Post date:** [June 10, 2015, 2:32am UTC](https://forum.ansible.com/t/parameterize-include-question-possible-bug/18427/2 "2015-06-10T02:32:18Z")

</div>

Hm…

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.

Thanks!

---

<div class="post-metadata">

**Author:** ![Giovanni\_Tirloni](https://avatars.discourse-cdn.com/v4/letter/g/71c47a/32.png) [@Giovanni\_Tirloni](https://forum.ansible.com/u/Giovanni_Tirloni)\
**Post date:** [June 10, 2015, 3:15am UTC](https://forum.ansible.com/t/parameterize-include-question-possible-bug/18427/3 "2015-06-10T03:15:06Z")

</div>

I think you are missing a "- " before those includes.

- name: blah  
&nbsp;&nbsp;hosts: blah  
&nbsp;&nbsp;...  
- include: blah.yml  
- include: bleh.yml

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).

You can do this:

- include: "{{ ansible\_distribution}}.yml"

---

<div class="post-metadata">

**Author:** ![benno\_joy](https://avatars.discourse-cdn.com/v4/letter/b/73ab20/32.png) [@benno\_joy](https://forum.ansible.com/u/benno_joy)\
**Post date:** [June 10, 2015, 3:29am UTC](https://forum.ansible.com/t/parameterize-include-question-possible-bug/18427/4 "2015-06-10T03:29:23Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![Michael\_Johnson1](https://avatars.discourse-cdn.com/v4/letter/m/dec6dc/32.png) [@Michael\_Johnson1](https://forum.ansible.com/u/Michael_Johnson1)\
**Post date:** [June 11, 2015, 5:41am UTC](https://forum.ansible.com/t/parameterize-include-question-possible-bug/18427/5 "2015-06-11T05:41:46Z")

</div>

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:

[https://github.com/therevmj/ansible-oddities/blob/master/play.yml](https://github.com/therevmj/ansible-oddities/blob/master/play.yml)

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.

---

<div class="post-metadata">

**Author:** ![Michael\_Johnson1](https://avatars.discourse-cdn.com/v4/letter/m/dec6dc/32.png) [@Michael\_Johnson1](https://forum.ansible.com/u/Michael_Johnson1)\
**Post date:** [June 12, 2015, 9:29am UTC](https://forum.ansible.com/t/parameterize-include-question-possible-bug/18427/6 "2015-06-12T09:29:05Z")

</div>

I suppose maybe it is time to file this as a bug in github? I'll do that over the weekend unless I hear something to the contrary. Thanks!

---

<div class="post-metadata">

**Author:** ![Michael\_Johnson1](https://avatars.discourse-cdn.com/v4/letter/m/dec6dc/32.png) [@Michael\_Johnson1](https://forum.ansible.com/u/Michael_Johnson1)\
**Post date:** [June 14, 2015, 6:16am UTC](https://forum.ansible.com/t/parameterize-include-question-possible-bug/18427/7 "2015-06-14T06:16:46Z")

</div>

I have created the following issue in github: [https://github.com/ansible/ansible/issues/11258](https://github.com/ansible/ansible/issues/11258)
