facts from set_fact aren't working

I’m setting 2 facts from a custom filter, which appears to be working, but when I go to use those facts in the playbook they aren’t there…

set_fact:
ilom_gw: “{{ ilom_ip | ilom_net(item.gateway,item.mask) }}”
ilom_mask: “{{ ilom_ip | ilom_net(item.gateway,item.mask, return_value=‘mask’) }}”
with_items: iloms

here’s the output of that task:

{
    "changed": false,
    "msg": "All items completed",
    "results": [
        {
            "_ansible_no_log": false,
            "ansible_facts": {
 **"ilom_gw": "10.224.64.1",**
 **"ilom_mask": "255.255.248.0"**
            },

as you can see both ilom_gw and ilom_mask are set here, but then:

debug: var=ilom_gw

[mgmt_port:debug] ilom_gw
	2016-10-26 15:31:29+00:00 (0:01:05)
	Changed = False
	JSON        : {
    "_ansible_no_log": false,
    "_ansible_verbose_always": true,
    "changed": false, 
     **"ilom_gw": false**
}


  debug: var=ilom_mask
[mgmt_port:debug] ilom_mask
	2016-10-26 15:31:30+00:00 (0:01:06)
	Changed = False
	JSON        : {
    "_ansible_no_log": false,
    "_ansible_verbose_always": true,
    "changed": false,
    **"ilom_mask": false**
}

And I swear when I tested this yesterday it worked as expected, but then today it’s broken… what am I missing?





Ok…found why, but I’m unsure how to fix. So iloms as defined in my group_vars is:

iloms:

  • gateway: 10.224.64.1

mask: 255.255.248.0

  • gateway: 10.85.0.1

mask: 255.255.254.0

  • gateway: 10.234.50.161

mask: 255.255.255.224

if the ilom.gateway/ilom.mask pair is the last in list, then ilom_gw and ilom_mask get set and are usable. If the pair is not last then they get set to false (because they did not match the filter) how can I specify a “found first” and exit the loop when a match is made?

and got it working…

replaced the
iloms:
-gateway: xxxx
mask: xxxxx

format with
iloms: [‘10.85.0.1/255.255.254.0’,‘10.234.50.161/255.255.255.224’,‘10.224.64.1/255.255.248.0’]

where each element is the gw/mask pair and got rid of the “with_items” the filter was modified to parse all the elements, check to see which set matched and return only the correct pairing

So, instead of looping through the list items, I pass them all at once and the filter does all the heavy lifting.