Chef - How to get the output of a command to a Ruby variable
Asked Answered
G

1

6

Chef - How to get the output of a command to a Ruby variable

I have the below scenario where i grep for a file

command "ls /filder1 | grep .txt"

grep gives an output of the filename/filenames if they exists .,

I want to store the output to a ruby variable and use it in the template to generate a config file.

How do i do that ?

Grew answered 13/6, 2013 at 8:42 Comment(0)
F
11

Chef is Ruby so you can use backticks output = `find /filder1 | grep .txt`

Fidelfidela answered 13/6, 2013 at 9:13 Comment(3)
but how to do that on the node?Emetic
Chef-Solo and variants runs exclusively on the node. Chef Client does some things to figure out what to run, downloads the needed files, then basically runs chef-solo ( at least last I looked in verison 10 and 11 ). It will have the results from the node running it as far as I knowFidelfidela
Won't that get executed during the compilation pass through, as opposed to when Chef is running the converge process?Ary

© 2022 - 2024 — McMap. All rights reserved.