custom facts with non-root account

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

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

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