Issues encountered on upgrading from 0.9 to 1.0

Playbooks I wrote for 0.9 gave errors

First, the thirsty parameter stopped working with the copy module. I think I saw somewhere else that this had been changed to force, so I updated it.
Second, and more importantly, the following stopped working:

copy:
src=$ANSIBLE_PATH/templates/sudoers
dest=/etc/sudoers

group_vars/all defines ANSIBLE_PATH and this definitely worked in 0.9
I also have include statements like the following:

include: $ANSIBLE_PATH/tasks/task1.yml

that also now give an error. Changing over to full paths corrects the issue.

I’m wondering if I somehow messed up my installation because I haven’t heard this reported by anyone else?

Ok, so 1.0 has been out for a long time and haven't heard any errors
about these things. To me it sounds like you may not have
$ANSIBLE_PATH defined in scope somewhere. Where did you have it set?

(I don't think we ever released 'thirsty' for the copy module, it was
force prior to release in 1.0-devel IIRC. I could be wrong. In any
event, thirsty was a terrible name, and those responsible have been
sacked!)

--Michael

OK I’ve found the bug.
There’s no issue with copy, but there is with include. If the group_vars/all file is specifically included in the vars_files: section, the parametrized-path in the include works, otherwise it does not. The behavior should be the same.

To show/hide the problem, uncomment the vars_files section in the test below.

group_vars/all:

Oh, yeah, you can't use inventory variables in include paths, because
they aren't in scope at playbook processing time.

This is because every object being included needs to get the same
things to include.

If you want conditional behavior around includes, you can do things
like attach a conditional to the include, like so:

- include: blarg
  when_string: ${ansible_distribution} == 'CentOS'

And that will still import the tasks on everything but affix the
conditional on all of the tasks in the included file.

Wait Michael, I’m trying to grasp this, so please bear with me.

Ohhhhh - I think I got it. You’re saying the notion of inventory (groups_vars/ host_vars) is distinct from the notion of vars/vars_files?Just double confirming so I don’t miss anything in my understanding; I was (naively) mixing them up so far - I will henceforth place all vars files under the separate vars folder - and emphasize this in our internal best-practices.

Secondly:

  • include: blarg
    when_string: ${ansible_distribution} == ‘CentOS’

Wow, this works? What are the restrictions on “ansible_distribution”? can it be an inventory variable (I assume not) ?
And you’re saying this is semantically equivalent to all actions in the included file having the “when_string” …
Holy moly … this is damn powerful.

Does this work with only_if as well?

group_vars/host_vars are inventory specific variables that vary by
host and group.

Variables loaded by vars_files CAN hinge on inventory and group
variables, and often do, but include paths may not hinge on such
things.

In general, usage of vars_files is almost always replaced by keeping
variables in group_vars/host_vars, but not always, and you are welcome
to use both depending on the use case.

It is fact true that you can use facts as well as inventory variables
in conditionals, without restriction, and it does work on only_if as
well.

Note that this "affix the conditionals to the include" only works on
task includes, not playbook includes.

OK good.
My sincere counsel is to enhance the documentation on include to mention both of these restrictions:

  • include paths can only be derived from vars/vars_files but NOT inventory variables
  • task (but not playbook) includes can be used with conditionals, and are equivalent to putting the conditional on each included action
    (I assume: this works like an AND on existing conditionals; this is recursive to arbitrary include depths)

Again, this is superbly powerful, I will utilize this immediately and simplify the implementation of a lot of use-cases.

Thanks.

Yep, I agree. If you can, please file a github ticket about these
doc items so we don't forget!

We should mention this when we talk about includes.

I think the conditional example is already documented, but I need to check.

--Michael

Ticket #2403