- From: Matt Ray <
>
- To:
- Cc:
- Subject: [chef] Re: Re: Capture output from a command or read contents from a file
- Date: Tue, 17 Jan 2012 15:44:47 -0600
Take a look at using Mixlib::ShellOut (previously Chef::ShellOut).
https://github.com/opscode/mixlib-shellout
Here's an outdated example (needs to be updated to Mixlib from Chef).
https://github.com/opscode/cookbooks/blob/master/drbd/recipes/pair.rb#L49
Thanks,
Matt Ray
Senior Technical Evangelist | Opscode Inc.
| (512) 731-2218
Twitter, IRC, GitHub: mattray
On Tue, Jan 17, 2012 at 3:26 PM, Hector Castro
<
>
wrote:
>
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.