# trouble with custom facts

**URL:** <https://forum.ansible.com/t/trouble-with-custom-facts/12939>\
**Category:** Ansible Project\
**Created:** [June 11, 2013, 1:33am UTC](https://forum.ansible.com/t/trouble-with-custom-facts/12939 "2013-06-11T01:33:37Z")\
**Posts on this page:** 10\
**Page:** 1

<div class="post-metadata">

**Author:** ![David\_Birdsong](https://avatars.discourse-cdn.com/v4/letter/d/bb73d2/32.png) [@David\_Birdsong](https://forum.ansible.com/u/David_Birdsong)\
**Post date:** [June 11, 2013, 1:33am UTC](https://forum.ansible.com/t/trouble-with-custom-facts/12939/1 "2013-06-11T01:33:37Z")

</div>

I’ve written a simple module that spits back ansible facts, but I can’t get the following task to show any of the values on debug.

Here’s the output from test-module:

---

<div class="post-metadata">

**Author:** ![Michael\_DeHaan2](https://avatars.discourse-cdn.com/v4/letter/m/da6949/32.png) [@Michael\_DeHaan2](https://forum.ansible.com/u/Michael_DeHaan2)\
**Post date:** [June 11, 2013, 2:30am UTC](https://forum.ansible.com/t/trouble-with-custom-facts/12939/2 "2013-06-11T02:30:46Z")

</div>

Using 1.2, this is {{ ansible\_data\_mounts }}, we fixed the variable syntax because the other stuff was confusing, but I think you want ${ansible\_data\_mounts}

---

<div class="post-metadata">

**Author:** ![Michael\_DeHaan2](https://avatars.discourse-cdn.com/v4/letter/m/da6949/32.png) [@Michael\_DeHaan2](https://forum.ansible.com/u/Michael_DeHaan2)\
**Post date:** [June 11, 2013, 2:31am UTC](https://forum.ansible.com/t/trouble-with-custom-facts/12939/3 "2013-06-11T02:31:04Z")

</div>

also, 1.2 supports just “with\_items: ansible\_data\_mounts”

---

<div class="post-metadata">

**Author:** ![David\_Birdsong](https://avatars.discourse-cdn.com/v4/letter/d/bb73d2/32.png) [@David\_Birdsong](https://forum.ansible.com/u/David_Birdsong)\
**Post date:** [June 11, 2013, 2:59am UTC](https://forum.ansible.com/t/trouble-with-custom-facts/12939/4 "2013-06-11T02:59:12Z")

</div>

> also, 1.2 supports just “with\_items: ansible\_data\_mounts”

aside from the debug module and passing in verbose flags, is there other debugging i can enable somehow?

{{ ansible\_data\_mounts }}  
or  
${ansible\_data\_mounts }}  
or  
ansible\_data\_mounts (i just updated to 1.2)

do not return a list.

fatal: [10.100.1.43] =\> with\_items expects a list

again, test-module verifies the list output:

PARSED OUTPUT  
{  
“ansible\_facts”: {  
“ansible\_data\_mounts”: [  
{  
“dev\_id”: 93515511438,  
“name”: “/export/hda3$”  
}  
]  
},  
“changed”: true  
}

---

<div class="post-metadata">

**Author:** ![Michael\_DeHaan](https://avatars.discourse-cdn.com/v4/letter/m/c4cdca/32.png) [@Michael\_DeHaan](https://forum.ansible.com/u/Michael_DeHaan)\
**Post date:** [June 11, 2013, 3:00am UTC](https://forum.ansible.com/t/trouble-with-custom-facts/12939/5 "2013-06-11T03:00:31Z")

</div>

with\_items: ansible\_data\_mounts

---

<div class="post-metadata">

**Author:** ![David\_Birdsong](https://avatars.discourse-cdn.com/v4/letter/d/bb73d2/32.png) [@David\_Birdsong](https://forum.ansible.com/u/David_Birdsong)\
**Post date:** [June 11, 2013, 3:13am UTC](https://forum.ansible.com/t/trouble-with-custom-facts/12939/6 "2013-06-11T03:13:23Z")

</div>

> with\_items: ansible\_data\_mounts

ok, i’ll stick with that, but what invocation for the task: debug will give me elements?

debug: msg=$item.name or ${item.name} or “{{ item.name }}” or $item[‘name’] or item.name?

i’ve tried them all and none show data, “item.name” or something similar ie…not my data from the module.

---

<div class="post-metadata">

**Author:** ![Lorin\_Hochstein1](https://avatars.discourse-cdn.com/v4/letter/l/ce73a5/32.png) [@Lorin\_Hochstein1](https://forum.ansible.com/u/Lorin_Hochstein1)\
**Post date:** [June 11, 2013, 3:40am UTC](https://forum.ansible.com/t/trouble-with-custom-facts/12939/7 "2013-06-11T03:40:45Z")

</div>

David:

The text of this pull request has a nice trick on how to use templates to inspect variables: [https://github.com/ansible/ansible/pull/2455](https://github.com/ansible/ansible/pull/2455)

Lorin

---

<div class="post-metadata">

**Author:** ![David\_Birdsong](https://avatars.discourse-cdn.com/v4/letter/d/bb73d2/32.png) [@David\_Birdsong](https://forum.ansible.com/u/David_Birdsong)\
**Post date:** [June 11, 2013, 7:33am UTC](https://forum.ansible.com/t/trouble-with-custom-facts/12939/8 "2013-06-11T07:33:44Z")

</div>

I narrowed down the behavior–possibly a scoping issue.

If a module that emits custom facts is called inside of a with\_items loop, the ansible\_facts reported by the module are not registered.

I have a simple example.

a test module that spits out json and takes no arguments:

PARSED OUTPUT  
{  
“ansible\_facts”: {  
“ansible\_foo”: [  
{  
“color”: “blue”,  
“name”: “test”  
}  
]  
},  
“changed”: true  
}

a simple playbook: test.yml

---

<div class="post-metadata">

**Author:** ![Michael\_DeHaan2](https://avatars.discourse-cdn.com/v4/letter/m/da6949/32.png) [@Michael\_DeHaan2](https://forum.ansible.com/u/Michael_DeHaan2)\
**Post date:** [June 11, 2013, 10:38am UTC](https://forum.ansible.com/t/trouble-with-custom-facts/12939/9 "2013-06-11T10:38:13Z")

</div>

Right, fact modules aren’t really intended for use with\_items, as that would make it return an array and not the hash it is expecting.

---

<div class="post-metadata">

**Author:** ![David\_Birdsong](https://avatars.discourse-cdn.com/v4/letter/d/bb73d2/32.png) [@David\_Birdsong](https://forum.ansible.com/u/David_Birdsong)\
**Post date:** [June 11, 2013, 5:57pm UTC](https://forum.ansible.com/t/trouble-with-custom-facts/12939/10 "2013-06-11T17:57:54Z")

</div>

> Right, fact modules aren't really intended for use with\_items, as that  
> would make it return an array and not the hash it is expecting.

Fair enough.

I ended up solving by passing complex args to my module--the complex arg  
being the thing that I was looping on with\_items.
