[chef] Capture output from a command or read contents from a file


Chronological Thread 
  • From: Harlan Barnes < >
  • To:
  • Subject: [chef] Capture output from a command or read contents from a file
  • Date: Tue, 17 Jan 2012 16:05:23 -0500
  • Domainkey-signature: a=rsa-sha1; c=nofws; d=pobox.com; h=mime-version :reply-to:date:message-id:subject:from:to:content-type; q=dns; s=sasl; b=S7d42YYOPD64ZPDaWK8Dv09I08/xnDHPtujIfA/LGNyq3B221lNjB LQ5k70FFonLFTSJBelTdgAbSa+maaExnxcEssoiBijVvzU0Kjc78SSU74SMqv46L 2963tZ0GXK0y+fTtOVTGFyu+2XDE8pDKESge0ORwuY+H71GZ4ah/Io=

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.

§