Chef-solo - expand run_list?

Hello

Using chef-solo and Chef 11.8.2, how do I use "expand
http://www.rubydoc.info/gems/chef/Chef/RunList#expand-instance_method"
correctly?

I’d like to run certain recipes only then, if a precondition outside of
chef is met (if the system has been enrolled in IPA, which I don’t do with
chef). For this, I’ve got the following recipe[ew::ipa-check]:

ruby_block ‘Entferne -ipa recipes von der run list, falls IPA noch NICHT
initialisiert wurde’ do
block do
node.run_list.expand(node.chef_environment,
“disk”).run_list_items.each do |run_list_item|
node.run_list.remove(run_list_item) if run_list_item.end_with?
"-ipa"
end # of node.run_list.expand(node.chef_environment,
“disk”).run_list_items.each do |run_list_item|
end
not_if "getent passwd _ipa-check"
end # of ruby_block ‘Entferne -ipa recipes von der run list, falls IPA noch
NICHT initialisiert wurde’ do

This doesn’t work, though… For some reason,
“node.run_list.expand(node.chef_environment,
“disk”).run_list_items” is “empty” - the “.each” block isn’t run.

node.run_list returns/contains (per node.run_list.to_s): role[ew-ubuntu],
role[mgmt], role[hardened]

I also tried using node.expand!, but this didn’t work either… :frowning:

node_expanded = node.expand!(“disk”)
File.open("/tmp/debug.txt", ‘a’) { |file|
file.write(“node_expanded.run_list:\n” + node_expanded.run_list_items.to_s

  • “\n”); }

And /tmp/debug.txt contains:

node_expanded.run_list:
[]

Why is that? Am I doing it wrong again?

Thanks,
Alexander

what are you trying to do? expand is used for runlist expansion and
triggered way before compilation phase invoked, its somewhat internal API,
and invoking it inside a ruby_block resource feels very strange. we might
be able to help you better if you instead tell us what you ware trying to
achieve :-/

On Tue, Sep 29, 2015 at 6:50 AM, Alexander Skwar <
alexanders.mailinglists+nospam@gmail.com> wrote:

Hello

Using chef-solo and Chef 11.8.2, how do I use "expand
http://www.rubydoc.info/gems/chef/Chef/RunList#expand-instance_method"
correctly?

I’d like to run certain recipes only then, if a precondition outside of
chef is met (if the system has been enrolled in IPA, which I don’t do with
chef). For this, I’ve got the following recipe[ew::ipa-check]:

ruby_block ‘Entferne -ipa recipes von der run list, falls IPA noch NICHT
initialisiert wurde’ do
block do
node.run_list.expand(node.chef_environment,
“disk”).run_list_items.each do |run_list_item|
node.run_list.remove(run_list_item) if run_list_item.end_with?
"-ipa"
end # of node.run_list.expand(node.chef_environment,
“disk”).run_list_items.each do |run_list_item|
end
not_if "getent passwd _ipa-check"
end # of ruby_block ‘Entferne -ipa recipes von der run list, falls IPA
noch NICHT initialisiert wurde’ do

This doesn’t work, though… For some reason, “node.run_list.expand(node.chef_environment,
“disk”).run_list_items” is “empty” - the “.each” block isn’t run.

node.run_list returns/contains (per node.run_list.to_s): role[ew-ubuntu],
role[mgmt], role[hardened]

I also tried using node.expand!, but this didn’t work either… :frowning:

node_expanded = node.expand!(“disk”)
File.open("/tmp/debug.txt", ‘a’) { |file|
file.write(“node_expanded.run_list:\n” + node_expanded.run_list_items.to_s

  • “\n”); }

And /tmp/debug.txt contains:

node_expanded.run_list:
[]

Why is that? Am I doing it wrong again?

Thanks,
Alexander

Mid chef run run_list changes don’t affect the current run.

I think you’re looking at this backwards anyway, why not just wrap your IPA
recipe in an if statement (or the include statement for it).

In any case, looking at the run_list expansion code it seems that the items
go in the recipes attribute not run_list_items after calling expand. I
don’t see that expand takes any parameters either, although (old)
references to it show examples of calling it with parameters.

On 29 September 2015 at 08:49, Ranjib Dey dey.ranjib@gmail.com wrote:

what are you trying to do? expand is used for runlist expansion and
triggered way before compilation phase invoked, its somewhat internal API,
and invoking it inside a ruby_block resource feels very strange. we might
be able to help you better if you instead tell us what you ware trying to
achieve :-/

On Tue, Sep 29, 2015 at 6:50 AM, Alexander Skwar <
alexanders.mailinglists+nospam@gmail.com> wrote:

Hello

Using chef-solo and Chef 11.8.2, how do I use "expand
http://www.rubydoc.info/gems/chef/Chef/RunList#expand-instance_method"
correctly?

I’d like to run certain recipes only then, if a precondition outside of
chef is met (if the system has been enrolled in IPA, which I don’t do with
chef). For this, I’ve got the following recipe[ew::ipa-check]:

ruby_block ‘Entferne -ipa recipes von der run list, falls IPA noch NICHT
initialisiert wurde’ do
block do
node.run_list.expand(node.chef_environment,
“disk”).run_list_items.each do |run_list_item|
node.run_list.remove(run_list_item) if
run_list_item.end_with? "-ipa"
end # of node.run_list.expand(node.chef_environment,
“disk”).run_list_items.each do |run_list_item|
end
not_if "getent passwd _ipa-check"
end # of ruby_block ‘Entferne -ipa recipes von der run list, falls IPA
noch NICHT initialisiert wurde’ do

This doesn’t work, though… For some reason, “node.run_list.expand(node.chef_environment,
“disk”).run_list_items” is “empty” - the “.each” block isn’t run.

node.run_list returns/contains (per node.run_list.to_s):
role[ew-ubuntu], role[mgmt], role[hardened]

I also tried using node.expand!, but this didn’t work either… :frowning:

node_expanded = node.expand!(“disk”)
File.open("/tmp/debug.txt", ‘a’) { |file|
file.write(“node_expanded.run_list:\n” + node_expanded.run_list_items.to_s

  • “\n”); }

And /tmp/debug.txt contains:

node_expanded.run_list:
[]

Why is that? Am I doing it wrong again?

Thanks,
Alexander