chef shell out to hash (separator is new line)

786 Views Asked by At

I just have a recipe with content:

echo_example = shell_out("echo "line 1\nline 2")
if echo_example.exitstatus == 0 && echo_example
  node.rm('test')
  node.set['test'] = [echo_example.stdout.chomp]
end

Attribute output with knife is:

        "test": [
          "line 1\nline 2"
        ]

How to get this output using knife below?

        "test": [
          "line 1",
          "line 2"
        ]

Thanks

1

There are 1 best solutions below

1
On BEST ANSWER

I don't know if this is what you are looking for, but maybe you can split the output in the recipe, before putting it in the attribute. You can use String#split for this:

node.set['test'] = [echo_example.stdout.chomp.split("\n")]