- From: Hector Castro <
>
- To:
- Cc:
- Subject: [chef] Re: Capture output from a command or read contents from a file
- Date: Tue, 17 Jan 2012 16:26:54 -0500
This is an interesting case. I wrote a step yesterday to write the mdadm
configuration file and used the following:
execute "mdadm_detail" do
command "mdadm --detail --scan >> /etc/mdadm.conf"
not_if "cat /etc/mdadm.conf | grep ARRAY"
end
Outside of capturing the `mdadm --detail --scan` output using Ruby and
passing it to `mdadm.conf` through template variables, do people have
alternate approaches?
--
Hector
On Jan 17, 2012, at 4:05 PM, Harlan Barnes wrote:
>
What's the proper way to read output from a command or contents from a file
>
to use in a variable (to pass to a template for example) in a chef recipe?
>
Or is this bad form in some way?
>
>
I couldn't figure out how to do it with a built in resource so I gave up
>
and went to some ruby ... but weird things happen. It seems to execute the
>
ruby code in the wrong place (too early ... before figlet is installed).
>
I'm probably doesn't something wrong, however.
>
>
Any suggestions?
>
>
# installs the figlet RPM
>
include_recipe "figlet"
>
>
banner = ''
>
io = IO.popen("/usr/bin/figlet -w 160 #{node.name}")
>
io.each do |line|
>
banner += line
>
end
>
>
template "/etc/motd" do
>
source "motd.erb"
>
mode 0644
>
variables(
>
:banner => banner
>
)
>
end
Archive powered by MHonArc 2.6.16.