I'm reading that a shell command can be executed from custom facts with Facter::Core::Execution.exec
. I've made a fact with the following code:
Facter.add(:controller_id) do
setcode do
Facter::Core::Execution.exec('/usr/bin/jq -r .device._id /var/lib/mylib/system.json')
end
end
When I run the command stand alone like /usr/bin/jq -r .device._id /var/lib/mylib/system.json
on an agent it returns a string. But when I run the fact on my agent with puppet agent -t
PuppetDb doesn't contain the new fact.
I can see that the agent sees the new fact code because it tells me my code has changed:
Notice: /File[/opt/puppetlabs/puppet/cache/lib/facter/controller_id.rb]/content: content changed '{md5}c3567db500497e3586617bfed072ca6d' to '{md5}bb617198c5612eee365b5af8d410d4bc'
But no error is returned telling me why the fact wasn't saved. Does anyone know what might be causing this issue?