custom facts with non-root account

48 views
Skip to first unread message

Uwe Bartels

unread,
Apr 18, 2016, 10:45:17 AM4/18/16
to Ansible Project
Hiho,

I'm currently working with most recent ansible in a very restricted system environment, e.g. I don't have root access.

now I'm gathering data via shell commands and register.
E.g.
- name: check for java installation
  shell: ls {{ installdir }}
  register: installdircontent

I'd like to gather information via facts, because the "PLAY RECAP" shows "changed=xx", but I'm only collecting information and don't change, when everything is fine.

custom facts can only placed in /etc/ansible/fact.d as described in the docs.
Is there any possibility to gather facts with non-root permissions?

Best Regards,
Uwe

Matt Davis

unread,
Apr 21, 2016, 6:46:44 PM4/21/16
to Ansible Project
Yes, you just need to call the setup module yourself (instead of letting gather_facts call it for you) and pass fact_path to a location you have control over. eg:

- hosts: myhosts
  gather_facts: no
  tasks:
  # calling setup manually will still store all the facts normally
  - setup: 
      fact_path: /home/me/myfacts
  - shell: echo "do stuff"

-Matt

Johannes Kastl

unread,
May 3, 2016, 3:21:32 AM5/3/16
to ansible...@googlegroups.com
On 18.04.16 16:44 Uwe Bartels wrote:

> I'd like to gather information via facts, because the "PLAY RECAP" shows
> "changed=xx", but I'm only collecting information and don't change, when
> everything is fine.

Apart from calling setup, like Matt suggested, one idead is to use
changed_when to describe when your task should be reported as changed.

Johannes


signature.asc
Reply all
Reply to author
Forward
0 new messages