If I want an action to only run on Centos I can use when_string:-
- name: ensure package absent
action: yum name=$item state=absent
when_string: $ansible_distribution == 'Centos'
with_items:
- fprintd
However if I have a set of things that are specific to an OS, and move them into their own task file, then this syntax does not work:-
- name: Basic Package setup
include: tasks/basic_centos_packages.yml
when_string: $ansible_distribution == 'Centos'
It executes for every host, no matter what OS/distribution.
Is this what is expected?
Nigel.
includes directives always get executed, not influenced by
conditionals, you might want to add the when_ inside the included
file.
Additionally, the app really should yell at you when you do one of
these things. I'm not sure why task.py didn't already handle that,
but it should.
Michael DeHaan wrote:
Additionally, the app really should yell at you when you do one of
these things. I'm not sure why task.py didn't already handle that,
but it should.
Warning of things that don't work as a naive user might expect would be good.
I can see *why* this is like this - presumably its a case of the initial pass through the playbook expands the whole thing into a single (yaml like) data structure by expanding the includes.
However being able to put conditionals onto some form of grouping rather than adding the conditional to each action would be good - I have just edited a dozen or so actions with the same thing on each which feels messy (and error prone). Maybe a way to have a conditional/loop and a list of further actions under that?
Nigel.
We discussed this in IRC, it would make a nice feature (conditional
auto unrolled to tasks on inclusion).
I'll put this on my list, but I have a few things in front, feel free
to tackle and submit patches.
Brian Coca wrote:
We discussed this in IRC, it would make a nice feature (conditional
auto unrolled to tasks on inclusion).
I'll put this on my list, but I have a few things in front, feel free
to tackle and submit patches.
I'll have a look - although I have something else I am working on with ansible in my queue first.
Nigel.
Nigel Metheringham wrote:
Michael DeHaan wrote:
Additionally, the app really should yell at you when you do one of
these things. I'm not sure why task.py didn't already handle that,
but it should.
I've added this on devel.
Warning of things that don't work as a naive user might expect would be
good.
I can see *why* this is like this - presumably its a case of the initial
pass through the playbook expands the whole thing into a single (yaml
like) data structure by expanding the includes.
However being able to put conditionals onto some form of grouping rather
than adding the conditional to each action would be good - I have just
edited a dozen or so actions with the same thing on each which feels
messy (and error prone). Maybe a way to have a conditional/loop and a
list of further actions under that?
I've also added this on devel, so task includes and only_if/when_* now works
as expected.
Daniel