chef-infrachef-recipemixlib-shellout

Parsing issue with ruby Mixlib::ShellOut in chef


I'm trying to extend an existing cookbook where we use Mixlib::ShellOut to collect a fair amount of information about an Oracle install. Mostly it just works.

I'm trying to add a node attribute for where TFA is running - because that can vary depending on version. From the server itself, a simple ps -ef | grep tfa | grep java | awk '{print $NF}' gives me exactly what I need.

When I add that to the recipe as

tfa_home = ::Mixlib::ShellOut.new("ps -ef | grep tfa | grep java | awk '{print $NF}'")
tfa_home.run_command
node.normal['gbucs_oracledb']['orahome']['tfa_home'] = tfa_home.stdout.strip

The resulting output json seems to get a newline char as well as the string "$NF'":

"tfa_home": "/u01/app/19.0.0.0/grid/tfa/<hostname>/tfa_home\n$NF}'"

I've tried a couple variants of escaping the $NF, but no luck so far. Is there an obvious solution?


Solution

  • What about String.gsub ?

    tfa_home.stdout.strip.gsub(/\n\$NF}'/, '')