# Testing a group\_vars list and setting fact based on results...how?

**URL:** <https://forum.ansible.com/t/testing-a-group-vars-list-and-setting-fact-based-on-results-how/22769>\
**Category:** Ansible Project\
**Created:** [October 11, 2016, 5:40pm UTC](https://forum.ansible.com/t/testing-a-group-vars-list-and-setting-fact-based-on-results-how/22769 "2016-10-11T17:40:43Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Dayton\_Jones](https://avatars.discourse-cdn.com/v4/letter/d/22d042/32.png) [@Dayton\_Jones](https://forum.ansible.com/u/Dayton_Jones)\
**Post date:** [October 11, 2016, 5:40pm UTC](https://forum.ansible.com/t/testing-a-group-vars-list-and-setting-fact-based-on-results-how/22769/1 "2016-10-11T17:40:43Z")

</div>

I have a couple of lists defined in group\_vars along with a lookup to determine the defined IP for the ilom:

> 

> …ansbile/inventory/group\_vars/.yml
> 
> > ilom\_gateway:
> 
> > - 10.224.64.1
> 
> > - 10.85.0.1
> 
> > - 10.234.50.161
> 
> > ilom\_mask:
> 
> > - 255.255.248.0
> 
> > - 255.255.254.0
> 
> > - 255.255.255.224
> 
> > ilom\_ip: “{{ lookup(‘dig’, ‘mgmt-’ + ansible\_local.system\_facts.host\_serial + ‘.example.com’) }}”

I need a way, in the playbook, to test and compare the ilom\_gateway values to the ilom\_ip – if it’s in the same subnet use that gateway and mask to configure the ilom. My question is, how? Would it be better to combine the lists (gw:mask) and split then test?

---

<div class="post-metadata">

**Author:** ![Dick\_Davies](https://avatars.discourse-cdn.com/v4/letter/d/b9e5f3/32.png) [@Dick\_Davies](https://forum.ansible.com/u/Dick_Davies)\
**Post date:** [October 11, 2016, 6:45pm UTC](https://forum.ansible.com/t/testing-a-group-vars-list-and-setting-fact-based-on-results-how/22769/2 "2016-10-11T18:45:47Z")

</div>

I'd make the information a different shape if i was you, rather than  
trying to loop over 2 data structures. Something like

iloms:  
&nbsp;&nbsp;- gateway: 10.224.64.1  
&nbsp;&nbsp;&nbsp;&nbsp;mask: 255.255.248.0  
&nbsp;&nbsp;- gateway: 10.85.0.1  
&nbsp;&nbsp;&nbsp;&nbsp;mask: 255.255.254.0  
&nbsp;&nbsp;- gateway: 10.234.50.161  
&nbsp;&nbsp;&nbsp;&nbsp;mask: 255.255.255.224

and use with\_items: iloms, accessing item.gateway and item.mask.

---

<div class="post-metadata">

**Author:** ![Dayton\_Jones](https://avatars.discourse-cdn.com/v4/letter/d/22d042/32.png) [@Dayton\_Jones](https://forum.ansible.com/u/Dayton_Jones)\
**Post date:** [October 11, 2016, 6:49pm UTC](https://forum.ansible.com/t/testing-a-group-vars-list-and-setting-fact-based-on-results-how/22769/3 "2016-10-11T18:49:06Z")

</div>

Ah yes, that makes better sense. But I’m still at a loss how I could determine the correct gw/mask to use after comparing the gateway to the ilom\_ip … depending on location, there could be any from from one gateway/mask to 4 and I need to make sure the correct one is selected…
