# block statements?

**URL:** <https://forum.ansible.com/t/block-statements/16605>\
**Category:** Ansible Project\
**Created:** [October 24, 2014, 9:46pm UTC](https://forum.ansible.com/t/block-statements/16605 "2014-10-24T21:46:44Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Ian\_Denhardt](https://avatars.discourse-cdn.com/v4/letter/i/7feea3/32.png) [@Ian\_Denhardt](https://forum.ansible.com/u/Ian_Denhardt)\
**Post date:** [October 24, 2014, 9:46pm UTC](https://forum.ansible.com/t/block-statements/16605/1 "2014-10-24T21:46:44Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![Brian\_Coca1](https://avatars.discourse-cdn.com/v4/letter/b/278dde/32.png) [@Brian\_Coca1](https://forum.ansible.com/u/Brian_Coca1)\
**Post date:** [October 24, 2014, 10:54pm UTC](https://forum.ansible.com/t/block-statements/16605/2 "2014-10-24T22:54:26Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![James\_Cammarata](https://avatars.discourse-cdn.com/v4/letter/j/7c8e57/32.png) [@James\_Cammarata](https://forum.ansible.com/u/James_Cammarata)\
**Post date:** [October 25, 2014, 11:51am UTC](https://forum.ansible.com/t/block-statements/16605/3 "2014-10-25T11:51:28Z")

</div>

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!
