# Dynamic Groups In Custom Dynamic Inventory

**URL:** <https://forum.ansible.com/t/dynamic-groups-in-custom-dynamic-inventory/25921>\
**Category:** Ansible Project\
**Created:** [November 3, 2017, 5:45pm UTC](https://forum.ansible.com/t/dynamic-groups-in-custom-dynamic-inventory/25921 "2017-11-03T17:45:06Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![gforster](https://sea1.discourse-cdn.com/ansible/user_avatar/forum.ansible.com/gforster/32/535_2.png) [@gforster](https://forum.ansible.com/u/gforster)\
**Post date:** [November 3, 2017, 5:45pm UTC](https://forum.ansible.com/t/dynamic-groups-in-custom-dynamic-inventory/25921/1 "2017-11-03T17:45:06Z")

</div>

I have a custom dynamic inventory whose source data is basically a custom flat-file database that consists of a hostname and a bunch of key=value pairs. In the dynamic inventory, I’m using those key=value pairs as hostvars. I currently do not have any defined groups.

What I would like to do is create groups on the fly using the hostvars. e.g. If I want to run a playbook against all of the hosts in the dynamic inventory with key=value pair of production=false, then run that same playbook against all those with production=true, then run it against production=true _and_ platform=linux, etc.

I don’t think I should have to create a separate playbook for all of those, maybe I do. I would think there is a way to do that via command-line arguments or somesuch. I just can’t find any straightforward documentation concerning that.

Thanks

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/ansible/original/1X/1882d9a01da5d8996a862359b0913cc568a39b84.svg) [@system](https://forum.ansible.com/u/system)\
**Post date:** [November 3, 2017, 10:09pm UTC](https://forum.ansible.com/t/dynamic-groups-in-custom-dynamic-inventory/25921/2 "2017-11-03T22:09:49Z")

</div>

This might be what you want.

[http://docs.ansible.com/ansible/devel/plugins/inventory/constructed.html](http://docs.ansible.com/ansible/devel/plugins/inventory/constructed.html)

---

<div class="post-metadata">

**Author:** ![gforster](https://sea1.discourse-cdn.com/ansible/user_avatar/forum.ansible.com/gforster/32/535_2.png) [@gforster](https://forum.ansible.com/u/gforster)\
**Post date:** [November 6, 2017, 5:27pm UTC](https://forum.ansible.com/t/dynamic-groups-in-custom-dynamic-inventory/25921/3 "2017-11-06T17:27:20Z")

</div>

This looks like the right idea…Just need to figure out how to get it working.
