# Common group\_by's or include a setup play before running playbook

**URL:** <https://forum.ansible.com/t/common-group-bys-or-include-a-setup-play-before-running-playbook/24372>\
**Category:** Ansible Project\
**Created:** [May 2, 2017, 9:28am UTC](https://forum.ansible.com/t/common-group-bys-or-include-a-setup-play-before-running-playbook/24372 "2017-05-02T09:28:51Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Fredrik\_Rambris](https://avatars.discourse-cdn.com/v4/letter/f/4af34b/32.png) [@Fredrik\_Rambris](https://forum.ansible.com/u/Fredrik_Rambris)\
**Post date:** [May 2, 2017, 9:28am UTC](https://forum.ansible.com/t/common-group-bys-or-include-a-setup-play-before-running-playbook/24372/1 "2017-05-02T09:28:51Z")

</div>

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?

---

<div class="post-metadata">

**Author:** ![Brian\_Coca](https://avatars.discourse-cdn.com/v4/letter/b/6de8d8/32.png) [@Brian\_Coca](https://forum.ansible.com/u/Brian_Coca)\
**Post date:** [May 2, 2017, 7:47pm UTC](https://forum.ansible.com/t/common-group-bys-or-include-a-setup-play-before-running-playbook/24372/2 "2017-05-02T19:47:40Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![Fredrik\_Rambris](https://avatars.discourse-cdn.com/v4/letter/f/4af34b/32.png) [@Fredrik\_Rambris](https://forum.ansible.com/u/Fredrik_Rambris)\
**Post date:** [May 3, 2017, 7:01am UTC](https://forum.ansible.com/t/common-group-bys-or-include-a-setup-play-before-running-playbook/24372/3 "2017-05-03T07:01:43Z")

</div>

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