Facter - custom fact - change directory then run command

asked 2017-02-22 12:12:32 -0500

eanderson753 gravatar image

I'm trying to create a new fact by changing to a directory, running a command, then storing the result as the fact.

The command run standalone is working but Facter is returning a null value

Facter.add('ruby_version') do
  setcode do
    result = Facter::Core::Execution.exec("cd /srv/#{app}/current && ruby --version")
  end
end

I appreciate any input on getting this working

edit retag flag offensive close merge delete

Comments

1

I would imagine the #{app} is causing issues.

puser gravatar imagepuser ( 2017-02-22 12:50:42 -0500 )edit

Try working 'up', aka, do `exec("echo /srv/#{app}/current")` and ensure that is what you would expect, then move to doing an `exec("echo /srv/#{app}/current")` etc until you see what isn't working as you expect

DarylW gravatar imageDarylW ( 2017-02-22 15:25:08 -0500 )edit

Yeah, there is some other supporting code that I removed but the #{app} value interpolates as I would expect. I also tried to enclose the execution line in a ruby CHDIR without success

eanderson753 gravatar imageeanderson753 ( 2017-02-23 09:02:27 -0500 )edit