# Delegate\_to, tags, when | "Good practise" when running playbook (or roles?) against a group of hosts, with some tasks limited only to a subset of this group.

**URL:** <https://forum.ansible.com/t/delegate-to-tags-when-good-practise-when-running-playbook-or-roles-against-a-group-of-hosts-with-some-tasks-limited-only-to-a-subset-of-this-group/17592>\
**Category:** Ansible Project\
**Created:** [February 22, 2015, 4:12pm UTC](https://forum.ansible.com/t/delegate-to-tags-when-good-practise-when-running-playbook-or-roles-against-a-group-of-hosts-with-some-tasks-limited-only-to-a-subset-of-this-group/17592 "2015-02-22T16:12:35Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![Jakub\_Muszynski](https://avatars.discourse-cdn.com/v4/letter/j/c68b51/32.png) [@Jakub\_Muszynski](https://forum.ansible.com/u/Jakub_Muszynski)\
**Post date:** [February 22, 2015, 4:12pm UTC](https://forum.ansible.com/t/delegate-to-tags-when-good-practise-when-running-playbook-or-roles-against-a-group-of-hosts-with-some-tasks-limited-only-to-a-subset-of-this-group/17592/1 "2015-02-22T16:12:35Z")

</div>

**This is a question of good practise**

**Introduction:**

I do have logic “Lines” on a way from my LB to Backend

> [LineA]  
> proxyA app\_type=proxy  
> frontendA app\_type=frontend  
> middlewareA app\_type=middleware

> [LineB]  
> proxyB app\_type=proxy  
> …

Since the apps are more complex than simple apache start stop. i did write custom modules with required logic to controll them (simplified example):

> proxysrv: with actions [suspend, activate]  
> restart: with actions [start, stop, restart], and app\_type arguments [frontend, middleware]

The tasks have to be played in certain order (suspend proxy, restart frontends and middleware, activate proxy)  
Now I can have a play like:

> * * *
> 
> - hosts: LineA
> - tasks:
> - name: suspend  
> proxysrv: action=suspend, when app\_type ==‘proxy’

> - name: restart FE

> restart: action=restart, app\_type=frontend, when app\_type ==‘frontend’
> 
> - name: restart MW  
> restart: action=restart, app\_type=middleware, when app\_type ==‘middleware’
> - name: activate  
> proxysrv: action=activate, when app\_type ==‘proxy’

I don’t like the “skipped” message during the run of a playbook, and the numbers in the final play statistics, that count the skipped hosts (as not changed).

**This is a question of good practise:**  
How would You create dependencies, that would apply specialized tasks on a subset of Your hosts group.

I guess that better way to solve the problem would be the use of **delegate\_to** (probably with “ **with\_items** ” or “ **tags** ”).  
I could register the ‘proxy\_hosts’, ‘frontend\_hosts’, ‘middleware\_hosts’ variables during an execution of the play and run tasks against them.  
I do not see yet use of tags here, the example would be nice.  
Any better idea?

What about roles. I would like to have a roles (proxy, restart role) and run them against subset of a hosts.
