Getting grouped attributes with node.attribute?

Hi there,

I try to do a only once command within a chef recipe which looks like the following:

execute “register_spacewalk” do
command "rhnreg_ks --serverUrl=http://spw0002.adm.nubon.com/XMLRPC --activationkey=1-d5ecd39c881c8202fd82f7bc930178be --force"
notifies :create, “ruby_block[register_spacewalk_run_flag]”, :immediately
not_if { node.attribute?(“register_spacewalk_run_flag”) }
end

ruby_block “register_spacewalk_run_flag” do
block do
node.set[“register_spacewalk_run_flag”] = true
node.save
end
action :nothing
End

The above command works fine, but I like to group all my spacewalk attribute variables under the group spacewalk.
For this, i tried to do the following:

execute “register_spacewalk” do
command "rhnreg_ks --serverUrl=http://spw0002.adm.nubon.com/XMLRPC --activationkey=1-d5ecd39c881c8202fd82f7bc930178be --force"
notifies :create, “ruby_block[register_spacewalk_run_flag]”, :immediately
not_if { node.attribute?(“spacewalk”“register_spacewalk_run_flag”) }
end

ruby_block “register_spacewalk_run_flag” do
block do
node.set[“spacewalk”][“register_spacewalk_run_flag”] = true
node.save
end
action :nothing
End

The node.set command works well, but I cannot do the node.attribute? Method on this attribute. I tried it with many different syntax like („spacewalk:register_spacewalk_run_flag“) or („spacewalk register_spacewalk_run_flag“) or ([“spacewalk“][“register_spacewalk_run_flag”]) or (”[spacewalk]“"[register_spacewalk_run_flag]“)

Do you have any idea how to solve the problem?

Thank you very much.

Greetings,
Kasimir

Le 2014-04-14 13:04, Christian Fröstl a écrit :

Hi there,

I try to do a only once command within a chef recipe which looks like the following:

execute "register_spacewalk" do
command "rhnreg_ks --serverUrl=http://spw0002.adm.nubon.com/XMLRPC --activationkey=1-d5ecd39c881c8202fd82f7bc930178be --force"
notifies :create, "ruby_block[register_spacewalk_run_flag]", :immediately
not_if { node.attribute?("register_spacewalk_run_flag") }
end
_ _
ruby_block "register_spacewalk_run_flag" do
block do
node.set["register_spacewalk_run_flag"] = true
node.save
end
action :nothing
E__nd

The above command works fine, but I like to group all my spacewalk attribute variables under the group spacewalk.
For this, i tried to do the following:

execute "register_spacewalk" do
command "rhnreg_ks --serverUrl=http://spw0002.adm.nubon.com/XMLRPC --activationkey=1-d5ecd39c881c8202fd82f7bc930178be --force"
notifies :create, "ruby_block[register_spacewalk_run_flag]", :immediately
not_if { node.attribute?("spacewalk""register_spacewalk_run_flag") }
end
_ _
ruby_block "register_spacewalk_run_flag" do
block do
node.set["spacewalk"]["register_spacewalk_run_flag"] = true
node.save
end
action :nothing
E__nd

The node.set command works well, but I cannot do the node.attribute? Method on this attribute. I tried it with many different syntax like _(„spacewalk:register_spacewalk_run_flag") or __(„spacewalk register_spacewalk_run_flag") or __(["spacewalk"]["register_spacewalk_run_flag"]) or __ _("[spacewalk]""[register_spacewalk_run_flag]")
_ _
Do you have any idea how to solve the problem?

Thank you very much.

Greetings,
Kasimir

Hi,

You should try:

not_if { node.attribute?("spacewalk") &&
node['spacewalk'].attribute?("register_spacewalk_run_flag") }

ruby evaluate from left to right, it will stop at first false found.

Regards,

Tensibai

Hi Tensibai,

It works well. Thank you very much.

Von: Tensibai <tensibai@iabis.netmailto:tensibai@iabis.net>
Antworten an: "chef@lists.opscode.commailto:chef@lists.opscode.com" <chef@lists.opscode.commailto:chef@lists.opscode.com>
Datum: Montag, 14. April 2014 13:39
An: "chef@lists.opscode.commailto:chef@lists.opscode.com" <chef@lists.opscode.commailto:chef@lists.opscode.com>
Betreff: [chef] Re: Getting grouped attributes with node.attribute?

Le 2014-04-14 13:04, Christian Fröstl a écrit :

Hi there,

I try to do a only once command within a chef recipe which looks like the following:

execute “register_spacewalk” do
command "rhnreg_ks --serverUrl=http://spw0002.adm.nubon.com/XMLRPC --activationkey=1-d5ecd39c881c8202fd82f7bc930178be --force"
notifies :create, “ruby_block[register_spacewalk_run_flag]”, :immediately
not_if { node.attribute?(“register_spacewalk_run_flag”) }
end

ruby_block “register_spacewalk_run_flag” do
block do
node.set[“register_spacewalk_run_flag”] = true
node.save
end
action :nothing
End

The above command works fine, but I like to group all my spacewalk attribute variables under the group spacewalk.
For this, i tried to do the following:

execute “register_spacewalk” do
command "rhnreg_ks --serverUrl=http://spw0002.adm.nubon.com/XMLRPC --activationkey=1-d5ecd39c881c8202fd82f7bc930178be --force"
notifies :create, “ruby_block[register_spacewalk_run_flag]”, :immediately
not_if { node.attribute?(“spacewalk”“register_spacewalk_run_flag”) }
end

ruby_block “register_spacewalk_run_flag” do
block do
node.set[“spacewalk”][“register_spacewalk_run_flag”] = true
node.save
end
action :nothing
End

The node.set command works well, but I cannot do the node.attribute? Method on this attribute. I tried it with many different syntax like („spacewalk:register_spacewalk_run_flag“) or („spacewalk register_spacewalk_run_flag“) or ([“spacewalk“][“register_spacewalk_run_flag”]) or (”[spacewalk]“"[register_spacewalk_run_flag]“)

Do you have any idea how to solve the problem?

Thank you very much.

Greetings,
Kasimir

Hi,

You should try:

not_if { node.attribute?(“spacewalk”) && node[‘spacewalk’].attribute?(“register_spacewalk_run_flag”) }

ruby evaluate from left to right, it will stop at first false found.

Regards,

Tensibai