# Remote custom facts not working

**URL:** <https://forum.ansible.com/t/remote-custom-facts-not-working/30884>\
**Category:** Ansible Project\
**Created:** [July 26, 2019, 9:26pm UTC](https://forum.ansible.com/t/remote-custom-facts-not-working/30884 "2019-07-26T21:26:16Z")\
**Posts on this page:** 9\
**Page:** 1

<div class="post-metadata">

**Author:** ![Kernel\_Panic](https://avatars.discourse-cdn.com/v4/letter/k/db5fbb/32.png) [@Kernel\_Panic](https://forum.ansible.com/u/Kernel_Panic)\
**Post date:** [July 26, 2019, 9:26pm UTC](https://forum.ansible.com/t/remote-custom-facts-not-working/30884/1 "2019-07-26T21:26:16Z")

</div>

Hello guys  
Im having an issue with custom remote facts that are not working, only local on the ansible server , this is what I have.

Querying remote server:

ansible mdo -m setup -a “filter=ansible\_local”  
mdo | SUCCESS =\> {  
“ansible\_facts”: {  
“ansible\_local”: {},  
“discovered\_interpreter\_python”: “/usr/bin/python”  
},  
“changed”: false  
}

On Local

ansible ansible -m setup -a “filter=ansible\_local”  
ansible | SUCCESS =\> {  
“ansible\_facts”: {  
“ansible\_local”: {  
“preferences”: {  
“general”: {  
“application”: “ansible”,  
“environment”: “production”  
}  
}  
},  
“discovered\_interpreter\_python”: “/usr/bin/python”  
},  
“changed”: false  
}

Remote facts file

cat /etc/ansible/facts.d/preferences.fact  
[general]  
environment=test  
application=test

ansible 2.8.2  
config file = /etc/ansible/ansible.cfg  
configured module search path = [u’/home/ansible/.ansible/plugins/modules’, u’/usr/share/ansible/plugins/modules’]  
ansible python module location = /usr/lib/python2.7/site-packages/ansible  
executable location = /bin/ansible  
python version = 2.7.5 (default, Jun 20 2019, 20:27:34) [GCC 4.8.5 20150623 (Red Hat 4.8.5-36)]

On the playbook I include to reload the facts

- name: Referesh Facts  
setup: filter=ansible\_local

Any hint appreciated  
Regards

---

<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:** [July 27, 2019, 8:18am UTC](https://forum.ansible.com/t/remote-custom-facts-not-working/30884/2 "2019-07-27T08:18:07Z")

</div>

Are you sure that the file is on the remote, mdo, and readable to the user logging in?  
This should confirm that:  
&nbsp;&nbsp;ansible mdo -m shell -a "ls -l /etc/ansible/facts.d/preferences.fact;cat /etc/ansible/facts.d/preferences.fact"

---

<div class="post-metadata">

**Author:** ![Kernel\_Panic](https://avatars.discourse-cdn.com/v4/letter/k/db5fbb/32.png) [@Kernel\_Panic](https://forum.ansible.com/u/Kernel_Panic)\
**Post date:** [July 27, 2019, 2:30pm UTC](https://forum.ansible.com/t/remote-custom-facts-not-working/30884/3 "2019-07-27T14:30:52Z")

</div>

You are right, but the playbook set permission the same for all server, but it seems there are not alike

[ansible@ansible ~]$ ansible mdo -m shell -a “ls -l /etc/ansible/facts.d/preferences.fact;cat /etc/ansible/facts.d/preferences.fact”  
mdo | FAILED | rc=1 \>\>  
ls: cannot access /etc/ansible/facts.d/preferences.fact: Permission denied  
cat: /etc/ansible/facts.d/preferences.fact: Permission deniednon-zero return code

[ansible@ansible ~]$ ansible ansible -m shell -a “ls -l /etc/ansible/facts.d/preferences.fact;cat /etc/ansible/facts.d/preferences.fact”  
ansible | CHANGED | rc=0 \>\>  
-rw-r–r-- 1 root root 53 Jul 26 19:25 /etc/ansible/facts.d/preferences.fact  
[general]  
environment=production  
application=ansible

- name: Create Ansible Fact Directory  
file:  
path: /etc/ansible/facts.d  
owner: root  
group: root  
mode: ‘0755’  
state: directory

- name: Copy custom facts  
copy:  
src: files/mdo-preferences.fact  
dest: /etc/ansible/facts.d/preferences.fact  
owner: root  
group: root  
mode: ‘0644’  
when: ansible\_hostname == ‘mdo-test-instance’

- name: Copy custom facts  
copy:  
src: files/ansible-preferences.fact  
dest: /etc/ansible/facts.d/preferences.fact  
owner: root  
group: root  
mode: ‘0644’  
when: ansible\_hostname == ‘ansible’

---

<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:** [July 27, 2019, 2:39pm UTC](https://forum.ansible.com/t/remote-custom-facts-not-working/30884/4 "2019-07-27T14:39:22Z")

</div>

Then it's probably the permissions on /etc/ansible (or /etc but not very likely)  
The user need read permission to all directories in the tree to be allowed access to the file.

---

<div class="post-metadata">

**Author:** ![Kernel\_Panic](https://avatars.discourse-cdn.com/v4/letter/k/db5fbb/32.png) [@Kernel\_Panic](https://forum.ansible.com/u/Kernel_Panic)\
**Post date:** [July 27, 2019, 2:42pm UTC](https://forum.ansible.com/t/remote-custom-facts-not-working/30884/5 "2019-07-27T14:42:15Z")

</div>

Maybe I should set the facts under ansible home directory instead? is that a good practice ?

thanks  
regrads

---

<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:** [July 27, 2019, 2:53pm UTC](https://forum.ansible.com/t/remote-custom-facts-not-working/30884/6 "2019-07-27T14:53:13Z")

</div>

I don't think anything is good or bad practice, it's just configuration.  
Since Ansible support changing the default path with fact\_path in ansible.cfg it's all up to you.

---

<div class="post-metadata">

**Author:** ![Kernel\_Panic](https://avatars.discourse-cdn.com/v4/letter/k/db5fbb/32.png) [@Kernel\_Panic](https://forum.ansible.com/u/Kernel_Panic)\
**Post date:** [July 27, 2019, 5:25pm UTC](https://forum.ansible.com/t/remote-custom-facts-not-working/30884/7 "2019-07-27T17:25:23Z")

</div>

Hi  
It was a directory permission issue, now I can read remote facts

[ansible@ansible playbooks]$ ansible mdo -m shell -a “ls -l /etc/ansible/facts.d/preferences.fact;cat /etc/ansible/facts.d/preferences.fact”  
mdo | CHANGED | rc=0 \>\>  
-rw-r–r-- 1 root root 63 Jul 27 12:19 /etc/ansible/facts.d/preferences.fact  
[general]  
environment=test  
application=test  
customhostname=mdo

But: the when condition is not working, maybe Im not referencing it correctly?

- name: Copy custom facts  
copy:  
src: files/mdo-preferences.fact  
dest: /etc/ansible/facts.d/preferences.fact  
#owner: root  
#group: root  
#mode: ‘0755’  
when: application == ‘test’

- name: Referesh Facts  
setup: filter=ansible\_local

Error:  
fatal: [mdo]: FAILED! =\> {“msg”: "The conditional check ‘application == ‘test’’ failed. The error was: error while evaluating conditional (application == ‘test’): ‘application’

Thanks!  
Regards

---

<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:** [July 27, 2019, 6:05pm UTC](https://forum.ansible.com/t/remote-custom-facts-not-working/30884/8 "2019-07-27T18:05:20Z")

</div>

I think you have left out crucial part of the error message.

I also think you have the chicken and the egg problem.  
If application is the same that you have in the local fact the first time you use it will fail, since the variable doesn't exist.

To reference you local fact you need to use ansible\_local, since your file is called preferences.fact the variables is stored under preferences.  
And in the file you have a section call general so the variables is stored under that too, so you need

&nbsp;&nbsp;ansible\_local.preferences.general.application

to reference application in your local fact.

---

<div class="post-metadata">

**Author:** ![Kernel\_Panic](https://avatars.discourse-cdn.com/v4/letter/k/db5fbb/32.png) [@Kernel\_Panic](https://forum.ansible.com/u/Kernel_Panic)\
**Post date:** [July 27, 2019, 6:18pm UTC](https://forum.ansible.com/t/remote-custom-facts-not-working/30884/9 "2019-07-27T18:18:09Z")

</div>

yup, that did the trick! thank you much!

Regards
