How to define a variable into an execution command

Hi,

I have a problem with my executing command string in chef, because it doesn’t see my declaration as a variable instead he will use the “name” of the variable. I tried it with attributes aso but the result will be the same :frowning:

This is my recipe:

Recipe:default.rb:

Update and restart ntp-deamon

NTP is the variable for Server1(first) and the Server(second)

execute “Set time to NTP Time now” do
command ‘/usr/sbin/ntpdate <%= node[:ntp][:first] %>’ => should be "command ‘/usr/sbin/ntpdate 217.0.0.1’ "
action :run
end

That is what chef will see if I execute it:

handle_command_failures’: /usr/sbin/ntpdate <%= node[:ntp][:first] %> returned 2, expected 0

Have anybody a similar problem and could resolve it?!

Best regards and thanks for the help
Andreas

On 16 Mar 2011, at 14:01, WEINHAPL Andreas wrote:

Hi,

I have a problem with my executing command string in chef, because it doesn’t see my declaration as a variable instead he will use the “name” of the variable. I tried it with attributes aso but the result will be the same L

This is my recipe:

Recipe:default.rb:

Update and restart ntp-deamon

NTP is the variable for Server1(first) and the Server(second)

execute "Set time to NTP Time now" do
command '/usr/sbin/ntpdate <%= node[:ntp][:first] %>' => should be “command ‘/usr/sbin/ntpdate 217.0.0.1’ “
action :run
end

That is what chef will see if I execute it:

handle_command_failures': /usr/sbin/ntpdate <%= node[:ntp][:first] %> returned 2, expected 0

Have anybody a similar problem and could resolve it?!

Best regards and thanks for the help
Andreas

<%= %> is ERB syntax and doesn't apply in recipe files. Instead you want to use ruby interpolation syntax:

command "ntpdate #{ node[:ntp][:first] }"

HTH,
-ash

HI Ash,

Many thanks! Youre right, I forget that :smiley:

Regards
andreas

From: Ash Berlin [mailto:ash_opscode@firemirror.com]
Sent: Mittwoch, 16. März 2011 15:08
To: chef@lists.opscode.com
Subject: [chef] Re: How to define a variable into an execution command

On 16 Mar 2011, at 14:01, WEINHAPL Andreas wrote:
Hi,

I have a problem with my executing command string in chef, because it doesn’t see my declaration as a variable instead he will use the “name” of the variable. I tried it with attributes aso but the result will be the same :frowning:

This is my recipe:

Recipe:default.rb:

Update and restart ntp-deamon

NTP is the variable for Server1(first) and the Server(second)

execute “Set time to NTP Time now” do
command ‘/usr/sbin/ntpdate <%= node[:ntp][:first] %>’ => should be "command ‘/usr/sbin/ntpdate 217.0.0.1’ "
action :run
end

That is what chef will see if I execute it:

handle_command_failures’: /usr/sbin/ntpdate <%= node[:ntp][:first] %> returned 2, expected 0

Have anybody a similar problem and could resolve it?!

Best regards and thanks for the help
Andreas

<%= %> is ERB syntax and doesn’t apply in recipe files. Instead you want to use ruby interpolation syntax:

command “ntpdate #{ node[:ntp][:first] }”

HTH,
-ash