[LineA]
proxyA app_type=proxy
frontendA app_type=frontend
middlewareA app_type=middleware
[LineB]
proxyB app_type=proxy
...
proxysrv: with actions [suspend, activate]
restart: with actions [start, stop, restart], and app_type arguments [frontend, middleware]
---
- hosts: LineA
- tasks:
- name:
proxysrv: action=suspend, when app_type =='proxy'
- name:
restart: action=restart, app_type=frontend, when app_type =='frontend'
- name:
restart: action=restart, app_type=middleware, when app_type =='middleware'
- name:
proxysrv: action=activate, when app_type =='proxy'
---
- hosts: all
tasks:
- name: Create a group of all hosts by app_type
group_by: key={{app_type}}
- debug: msg="groups={{groups}}"
run_once: true
- hosts: web:&some_other_group
tasks:
- debug: msg="play_hosts={{play_hosts}}"
run_once: true
would result in
TASK: [Create a group of all hosts by app_type] *******************************
changed: [web1] => {"changed": true, "groups": {"web": ["web1", "web2"], "load_balancer": ["web3"]}}
TASK: [debug msg="play_hosts={{play_hosts}}"] *********************************
ok: [web1] => {
"msg": "play_hosts=['web1']"
}
inventory:
[proxy]
web1 app_type=web
web2 app_type=web
web3 app_type=load_balancer
[some_other_group]
web1
web3