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.

15 views
Skip to first unread message

sirkubax

unread,
Feb 22, 2015, 11:12:35 AM2/22/15
to ansible...@googlegroups.com
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.
 
Reply all
Reply to author
Forward
0 new messages