# getting inventory properties as a list

**URL:** <https://forum.ansible.com/t/getting-inventory-properties-as-a-list/16525>\
**Category:** Ansible Project\
**Created:** [October 16, 2014, 12:49am UTC](https://forum.ansible.com/t/getting-inventory-properties-as-a-list/16525 "2014-10-16T00:49:54Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![David\_Judd](https://avatars.discourse-cdn.com/v4/letter/d/8797f3/32.png) [@David\_Judd](https://forum.ansible.com/u/David_Judd)\
**Post date:** [October 16, 2014, 12:49am UTC](https://forum.ansible.com/t/getting-inventory-properties-as-a-list/16525/1 "2014-10-16T00:49:54Z")

</div>

I have a playbook which performs a potentially destructive action, which I expect to run with --limit normally, and I would like to assert that all hosts which meet a certain condition are included in my --limit to avoid unexpected behavior. The particular use case is failing over a PostgreSQL master and updating all replicas correspondingly.

I don’t have a problem getting the list to validate against (I use an ansible\_local fact), but I can’t figure out how to get a property of each host present in hostvars as a list. So I want to be able to say something like:

> - name: validate all streaming replicas are in scope  
> assert:  
> that:
> - “{{ item }} in {{ hostvars.values()|map(attribute=‘ansible\_default\_ipv4’)|map(‘address’) }}”  
> with\_items: ansible\_local.academia.pg\_streaming\_replicas

> when: inventory\_hostname == old\_master

But “hostvars.values()|map(attribute=‘ansible\_default\_ipv4’)|map(‘address’)” doesn’t do what I expect, and neither does any variant I’ve tried. What’s the right way to get the list of IPs for all hosts that Ansible knows about?

-David

---

<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:** [October 20, 2014, 9:11pm UTC](https://forum.ansible.com/t/getting-inventory-properties-as-a-list/16525/2 "2014-10-20T21:11:42Z")

</div>

So pretty much limit in ansible works, so you shouldn’t feel the need to double check it.

If you must, I would do this, and keep in mind you don’t use “{{ }}” in conditionals in ansible.

- assert:  
that:
- item in play\_hosts  
with\_items: required\_servers
