- From: Noah Kantrowitz <
>
- To:
- Subject: [chef] Re: Changing the order of 'run_list'
- Date: Fri, 5 Jun 2015 11:17:01 -0700
This is not something you should generally do as changing the run list from
inside recipe code probably won't have the effect you expect. Notably it
won't have _any_ effect until the next run assuming the current one succeeds.
As to your specific question:
node.run_list.run_list_items.insert(node.run_list.find('role[base']),
'role[web]'). You can find more information in the Ruby documentation for
Array#insert and Enumerable#find.
--Noah
On Jun 5, 2015, at 11:09 AM, Tiago Cruz
<
>
wrote:
>
Hello Daniel, thanks for your time!
>
>
Could you please help with some example? I think that I don't get yet :(
>
>
- Try 1:
>
>
node.run_list.add("role[base]", --before, "role[web]")
>
>
[2015-06-05T17:51:29+00:00] ERROR: ruby_block[Add base before web]
>
(test::web line 7) had an error: NoMethodError: undefined method `before'
>
for Chef::Resource::RubyBlock
>
>
- Try 2:
>
>
node.run_list.add("role[base]", before, "role[web]")
>
>
[2015-06-05T17:53:01+00:00] ERROR: ruby_block[Add base before web]
>
(test::web line 7) had an error: NoMethodError: undefined method `before'
>
for Chef::Resource::RubyBlock
>
>
- Try 3:
>
>
node.run_list.add("role[base]", "before", "role[web]")
>
>
[2015-06-05T17:47:04+00:00] ERROR: ruby_block[Add base before web]
>
(test::web line 7) had an error: ArgumentError: wrong number of arguments
>
(3 for 1)
>
>
Thanks!
>
>
On Fri, Jun 5, 2015 at 12:19 PM, Daniel DeLeo
>
<
>
>
wrote:
>
>
>
On Friday, June 5, 2015 at 8:01 AM, Tiago Cruz wrote:
>
>
> Ohai!
>
>
>
> To add one recipe before other, I can use:
>
>
>
> knife node run_list add lasvegas1 'role[base]' --before 'role[web]'
>
>
>
> But I can't do this using recipe:
>
>
>
> if not node.run_list.roles.include?('base')
>
> ruby_block "Add base role before web" do
>
> block { node.run_list.add("role[base]").before("role[web]") }
>
> end
>
> end
>
>
>
> How can I do this?
>
>
>
> Thanks!
>
>
>
> --
>
> -- Tiago Cruz
>
>
The run list is just a ruby array, use ruby’s Array methods for this.
>
>
http://ruby-doc.org/core-2.2.0/Array.html#method-i-insert
>
>
--
>
Daniel DeLeo
>
>
>
>
>
>
>
--
>
-- Tiago Cruz
>
Attachment:
signature.asc
Description: Message signed with OpenPGP using GPGMail
Archive powered by MHonArc 2.6.16.