# Use setup module filter parameter to get results based on values of a fact

**URL:** <https://forum.ansible.com/t/use-setup-module-filter-parameter-to-get-results-based-on-values-of-a-fact/15696>\
**Category:** Ansible Project\
**Tags:** vmware\
**Created:** [July 17, 2014, 4:59pm UTC](https://forum.ansible.com/t/use-setup-module-filter-parameter-to-get-results-based-on-values-of-a-fact/15696 "2014-07-17T16:59:30Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![KSS](https://avatars.discourse-cdn.com/v4/letter/k/a587f6/32.png) [@KSS](https://forum.ansible.com/u/KSS)\
**Post date:** [July 17, 2014, 4:59pm UTC](https://forum.ansible.com/t/use-setup-module-filter-parameter-to-get-results-based-on-values-of-a-fact/15696/1 "2014-07-17T16:59:30Z")

</div>

Hi,

Is it possible to use the setup module along with the filter parameter to return something based on the value of fact?

For example, I want to quickly get a list of all my machines in ansible that are VMWare based using an ad-hoc command. I can run the following to get the vendor;

ansible -i inventory all -m setup -a “filter=ansible\_system\_vendor” -o  
10.0.XXX.XXX | success \>\> {“ansible\_facts”: {“ansible\_system\_vendor”: “VMware, Inc.”}, “changed”: false}  
10.0.XXX.XXX | success \>\> {“ansible\_facts”: {“ansible\_system\_vendor”: “VMware, Inc.”}, “changed”: false}

10.0.XXX.XXX | success \>\> {“ansible\_facts”: {“ansible\_system\_vendor”: “HP”}, “changed”: false}

And I can pipe the result though grep to get what I need, but is there any way to quickly list all hosts by the value of a certain fact?

Thanks.

---

<div class="post-metadata">

**Author:** ![Michael\_DeHaan1](https://avatars.discourse-cdn.com/v4/letter/m/5e9695/32.png) [@Michael\_DeHaan1](https://forum.ansible.com/u/Michael_DeHaan1)\
**Post date:** [July 18, 2014, 1:36am UTC](https://forum.ansible.com/t/use-setup-module-filter-parameter-to-get-results-based-on-values-of-a-fact/15696/2 "2014-07-18T01:36:59Z")

</div>

This may be useful, untested quick sketch though…

Take a look at the group\_by parameter to select all hosts where a fact has a certain value.

- hosts: all  
tasks:

- group\_by: key=ansible\_system\_vendor\_{{ ansible\_system\_vendor }}

- hosts: ansible\_system\_vendor\_HP  
tasks:

- debug: msg=“{{ inventory\_hostname }} is an HP”

---

<div class="post-metadata">

**Author:** ![KSS](https://avatars.discourse-cdn.com/v4/letter/k/a587f6/32.png) [@KSS](https://forum.ansible.com/u/KSS)\
**Post date:** [July 18, 2014, 9:02am UTC](https://forum.ansible.com/t/use-setup-module-filter-parameter-to-get-results-based-on-values-of-a-fact/15696/3 "2014-07-18T09:02:34Z")

</div>

Thanks for the reply.

Yep, I’ve already been doing that in a playbook, I just wondered if it was possible to do using an adhoc command. That way I can quickly run a command to say, list all machines running CentOS or all machines that are HP or based on any other fact.

I guess the answer is that the filter parameter of the setup doesn’t currently allow for more than matching on a fact name.

---

<div class="post-metadata">

**Author:** ![Michael\_DeHaan1](https://avatars.discourse-cdn.com/v4/letter/m/5e9695/32.png) [@Michael\_DeHaan1](https://forum.ansible.com/u/Michael_DeHaan1)\
**Post date:** [July 18, 2014, 11:47am UTC](https://forum.ansible.com/t/use-setup-module-filter-parameter-to-get-results-based-on-values-of-a-fact/15696/4 "2014-07-18T11:47:50Z")

</div>

It’s not possible to do this with /usr/bin/ansible currently.
