Dynamic hosts list in playbooks?

FWIW, I wrote code one day that allows this (14 lines!)
Check out https://github.com/jhoekx/ansible/commits/discover-groups

Basically, you just write a module that's similar to a custom facts
module, but instead of returning ansible_facts, you return a list of
groups in ansible_groups.

I didn't send a pull request for this because of the brainstorming Dag
mentioned and I'm not sure anymore of the right solution. This part is
simple and powerful though. If it's acceptable, I'm happy to send it
in.

Greetings,

Jeroen

The idea that we could scan hosts in one play and partition them based
on facts is appealing. I'd like to see some syntax that auto
partitions them automatically based on like facts instead though.
Think about automatically making a group of all my FreeBSD hosts, etc.

This directly relates to the EC2 discovery question posed earlier.

Something like a action_plugin called 'group_based_on'

hosts: all

tasks:
    - ...
    - group_based_on: ansible_os_type

And for everyone who responded:

{ ansible_os_type: 'BeOS' }

It would auto spawn a group named 'ansible_os_type_BeOS'

This could easily partition your hosts based on the value of any
arbitrary command, including register variables.

Make it so, #1?

I see offhand my proposal is less interesting if you have 50 playbooks
and a few masters and you don't know which ones you launch.

I think both are potentially useful, for very different reasons.