ansible/ansible — pull request #1457 by jhoekx (2012-10-26 13:24:31+00:00)
Title: Introduce a group_by playbook parameter to dynamically define groups.

Anything that returns a list or a string would do.

Examples:

```
---

- hosts: all
gather_facts: false
tasks:
- local_action: is_provisioned host=${inventory_hostname}
group_by: is_provisioned

- hosts: unprovisioned
gather_facts: false
tasks:
...provision...

```

With `is_provisioned` for a simple testcase:

```
#!/usr/bin/env python

def main():
module = AnsibleModule(
argument_spec = dict(
host=dict(required=True),
)
)

if module.params['host'] == 'firefly':
module.exit_json(is_provisioned=['unprovisioned'])
else:
module.exit_json(ok="ok")

# this is magic, see lib/ansible/module_common.py
#<>
main()
```

If you prefer not to introduce new playbook syntax, https://github.com/jhoekx/ansible/commits/discover-groups still applies, but has a magic 'ansible_groups' parameter that can be returned.