Common group_by's or include a setup play before running playbook

I want to have a way to globally define OS dependent variables. I currently am doing this with something like this at the top of my playbooks

`

  • name: Gather facts
    hosts: the_hosts_we_are_applying_playbook_on
    tags: always
    tasks:
  • group_by:
    key: os_family_{{ ansible_os_family | lower }}
    `

and define stuff in group_vars/os_family_redhat.yml etc.

I would like to have this globally so that I haven’t have to define this in every playbook. Is there a way to have a playbook run every time before the one defined on command line? I’m thinking of something like

ansible.cfg: [default] before_playbook = setup.yml

Could this be done with a plugin that is called after ‘setup’ has been called?

Soon, first need to merge this
https://github.com/ansible/ansible/pull/23001, which then makes this
possible https://github.com/ansible/ansible/pull/23374 (but you'll
need fact caching enabled).

Looks promising. Being able to manipulate groups in plugins would solve a bunch of problems.