I ’ ve written some custom facts that require sudo to be executed (Those are scripts that parse some files in /etc/) .
My custom facts scripts are of course not executed when ansible is gathering facts. On the other hand I need the facts gathered as ansible user.
My workaround for this is now:
`
`
Is there a feature to cover this problem? Maybe some way to tell ansible to complete nonsudo facts by sudo facts?
Thanks
"My custom facts scripts are of course not executed when ansible is gathering facts. "
I’m confused about this, do you mean “facts.d” facts?
If you are writing local facts they would in fact be gathered when you are gathering facts.
It seems you might be calling your own facts module and named it “setup”, which you should not do, really, but I’m unclear if you did.
You can also set “sudo: True” at play level.
It may be that you want to write a “my_facts” module instead, unless you have a specific need for facts.d.
Let me know a bit more info and we’ll get closer to the answer.
Thanks!
Sorry for the confusion.
I got a custom fact script on the remote machine.
/etc/ansible/facts.d/node_guid.fact
which looks like this:
`
#! /usr/bin/env python
import sys
import json
def get_prop(line):
return line.split(“=”)[1].strip()
try:
f = open(‘/etc/zypp/credentials.d/NCCcredentials’)
except IOError:
print(“{}”)
sys.exit(0)
context = {}
keys = [‘username’]
for line in f:
for key in keys:
if line.startswith(key):
context[key] = get_prop(line)
print json.dumps(context)
sys.exit(0)
`
'/etc/zypp/credentials.d/NCCcredentials' is set readable only for root. Therefore 'node_guid.fact' only returns facts as sudo. Which is the reason why I call the setup module with
sudo:yes``
Yeah that seems fine.
You will want to turn off “gather_facts” and call it explicitly.
What you are doing with site facts is a little weird, most folks would probably do a fact module and rather than calling it twice, split different things into different modules.