parameterize include question / possible bug

67 views
Skip to first unread message

Michael Johnson

unread,
Jun 8, 2015, 5:02:37 AM6/8/15
to ansible...@googlegroups.com
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] => {

    "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] => {

    "msg": "parameter=file"

}



Michael Johnson

unread,
Jun 9, 2015, 10:32:18 PM6/9/15
to ansible...@googlegroups.com
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!

Giovanni Tirloni

unread,
Jun 9, 2015, 11:15:13 PM6/9/15
to ansible...@googlegroups.com
I think you are missing a "- " before those includes.

- name: blah
hosts: blah
...
- 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"


On Tue, 09 Jun 2015 19:32 -0700, Michael Johnson <ther...@gmail.com>
wrote:
> --
> 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 ansible-proje...@googlegroups.com.
> To post to this group, send email to ansible...@googlegroups.com.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/ansible-project/bee3f4b2-8fcb-4d75-a0e7-e1b0c5af16cf%40googlegroups.com.
> For more options, visit https://groups.google.com/d/optout.

benno joy

unread,
Jun 9, 2015, 11:29:28 PM6/9/15
to ansible...@googlegroups.com
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.




Michael Johnson

unread,
Jun 11, 2015, 1:41:47 AM6/11/15
to ansible...@googlegroups.com
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.

Michael Johnson

unread,
Jun 12, 2015, 5:29:05 AM6/12/15
to ansible...@googlegroups.com
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!

Michael Johnson

unread,
Jun 14, 2015, 2:16:46 AM6/14/15
to ansible...@googlegroups.com
I have created the following issue in github:  https://github.com/ansible/ansible/issues/11258
Reply all
Reply to author
Forward
0 new messages