block statements?

Hey

Does ansible have a way of grouping multiple tasks into one (akin to a
block statement in many programming languages)? I've several tasks that
I want to (a) apply some common options to, such as sudo: yes, and (b)
do in a loop (with_items). I could put these in a separate role, but
that seems very heavyweight, and in my case I'm already inside of a role
that I'd like to be self-contained. I haven't been able to find anything
that lets me do this -- I tried hacking around it by putting an include
statement as the task, but got an error saying that using that with
with_items had been removed after being deprecated. That's more than
reasonable -- it's pretty ugly -- but I can't find a better way to do
this.

Thoughts?

-Ian

you can already do some of this, with variables and tags, with include
and role directives. But currently there is only one true block of
tasks and that is a play.

there is some work in ansible to create the block concept/object for
tasks but it is in early stages.

Hi Ian,

This is actually a feature we are currently working on, specifically as part of our “v2” refactoring Michael mentioned in another thread on this group. This will most likely be available in version 1.9 in the future, but for now using roles and include statements with tags is the best way to group related tasks.

Thanks!