- From: Daniel DeLeo <
>
- To:
- Subject: [chef] Re: Issue with changing nodes run_list from command line using "knife exec -E"
- Date: Mon, 5 Jan 2015 10:29:26 -0800
On Monday, January 5, 2015 at 4:55 AM,
wrote:
>
Hi guys,
>
>
What I need is to change nodes run_list basing on their tags and roles and
>
names etc.
>
>
For example I have multiple nodes with different roles etc.
>
>
And I would like to assign some particular recipe to nodes which met some
>
condition:
>
>
knife exec -E "nodes.find(:name => '*isec*') { |node| node.run_list <<
>
"recipe[foo]"; n.save }"
>
>
It will work for nodes which have *isec* in its names.
>
>
>
But what if I would like to use query something like:
>
>
knife exec -E "nodes.find(:name => '*isec*' AND :tags => 'tag_name' AND
>
:role => 'role_name') { |node| node.run_list << "recipe[foo]"; n.save }"
You’re mixing ruby syntax and Solr query syntax here. If you want all the
conditions to be AND’ed together, then you can pass a regular ruby Hash
object, e.g., :name => “NAME_QUERY”, :tags => “TAG_QUERY”, …
If you instead need to do something more complicated, you can pass a string
to `nodes.find` using the same syntax as you would with `knife search`.
For reference, the code that generates the query from the `nodes.find` call
is here:
https://github.com/opscode/chef/blob/005f75e158ce702bb28fd6199e9654b3d1115d3b/lib/chef/shell/model_wrapper.rb#L86-L92
HTH,
--
Daniel DeLeo
Archive powered by MHonArc 2.6.16.