# Problem returning IP address from custom fact

**URL:** <https://forum.ansible.com/t/problem-returning-ip-address-from-custom-fact/24478>\
**Category:** Ansible Project\
**Tags:** ubuntu\
**Created:** [May 12, 2017, 10:23pm UTC](https://forum.ansible.com/t/problem-returning-ip-address-from-custom-fact/24478 "2017-05-12T22:23:39Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![dbenson2492](https://avatars.discourse-cdn.com/v4/letter/d/c68b51/32.png) [@dbenson2492](https://forum.ansible.com/u/dbenson2492)\
**Post date:** [May 12, 2017, 10:23pm UTC](https://forum.ansible.com/t/problem-returning-ip-address-from-custom-fact/24478/1 "2017-05-12T22:23:39Z")

</div>

I see this problem when running a custom fact that is trying to return an IP address string.  
Ansible reports an empty string, but I see the correct output when I run the fact manually on the target.

Running Ansible 2.2.1.0 on Ubuntu 16.04.  
The Vagrant target is running Centos 6.  
(I’ve edited out the real IP address below.)

The fact is written like this:

#!/bin/bash  
KA\_ROLE=$(cat /var/log/keepalived-state)  
IP\_OWNED=$(ip addr | grep ‘/32’ | grep -Po ‘(\d+.){3}\d+’)  
cat \<\<EOF  
{  
“role” : “$KA\_ROLE”,  
“vip” : “$IP\_OWNED”  
}  
EOF

if I run the fact manually on the target it gives the expected output:

# ./keepalive.fact

{  
“role” : “MASTER”,  
“vip” : “my.expected.ip.address”  
}

But when I run with Ansible, I don’t get the VIP:

$ ansible -m setup -a “filter=ansible\_local” -i vagrant radius1  
radius1 | SUCCESS =\> {  
“ansible\_facts”: {  
“ansible\_local”: {  
“keepalive”: {  
“role”: “MASTER”,  
“vip”: “”  
}  
}  
},  
“changed”: false  
}

If I run the script on the target and redirect the output to a file,  
then rerun the setup module, I see the correct information is read by  
Ansible from the file.

# ./keepalive.fact \> test.fact

radius1 | SUCCESS =\> {  
“ansible\_facts”: {  
“ansible\_local”: {  
“keepalive”: {  
“role”: “MASTER”,  
“vip”: “”  
},  
“test”: {  
“role”: “MASTER”,  
“vip”: “my.expected.ip.address”  
}  
}  
},  
“changed”: false  
}

---

<div class="post-metadata">

**Author:** ![Kai\_Stian\_Olstad](https://avatars.discourse-cdn.com/v4/letter/k/e19adc/32.png) [@Kai\_Stian\_Olstad](https://forum.ansible.com/u/Kai_Stian_Olstad)\
**Post date:** [May 13, 2017, 1:34pm UTC](https://forum.ansible.com/t/problem-returning-ip-address-from-custom-fact/24478/2 "2017-05-13T13:34:52Z")

</div>

I first guess is that not all commands is in PATH when it's runs through Ansible.

Mot likely ip which in /sbin, use absolute path to the commands and see if that helps.
