$knife search node “recipes:cftp”
knife search node “hostname:zeus” -l | grep -C 10 recipes
metric: 256
proto: kernel
state: unknown
type: vnet
ohai_time: 1376978220.81941
os: linux
os_version: 3.5.0-34-generic
platform: ubuntu
platform_family: debian
platform_version: 12.04
recipes:
apt
ntp
cftp
cnfs::server
cinotify
nut
fail2ban
csquiddebproxy::server
csquiddebproxy
cbacula::client
OR other example:
knife search node “roles:ntp_server” -l | grep -C 10 roles
apt
ntp
cftp
cnfs::server
cinotify
nut
fail2ban
csquiddebproxy::server
csquiddebproxy
cbacula::client
roles:
ntp_server
nut_apcrt5000xl_serverroom_server
uptime: 6 days 21 hours 09 minutes 00 seconds
uptime_seconds: 594540
virtualization:
role: host
system: kvm
What is the difference between roles and recipes attributes. Why with
recipes search are not work ?
Thank you very much.
–
Best regards,
CVisionLab System Administrator
Vladmir Skubriev
Ranjib
August 20, 2013, 7:00am
2
Recipes and roles are two node attributes, populated during node building,
as part of chef run (check client.rb for phases in a chef run). Iteresting
values of these two attributes comes from run list expansions, which
populates an array of recipe as it parses the items in run list. Note, both
are automatic attributes, some thing similar to ohai.
Now,
if you want to check all recipes against a node, if you can use the
run_context.loaded_recipes (most probably). this trick will work as long as
you are searching against the current running node and the recipe you are
searching is included before the code block where you are checking this.
We internally use a handler that exposes these info as
node.chef_metrics.loaded_recipes (with few other staff).
def automatic_attrs
attributes.automatic
end
def automatic_attrs=(new_values)
attributes.automatic = new_values
end
# Return true if this Node has a given attribute, false if not. Takes either a symbol or
# a string.
#
# Only works on the top level. Preferred way is to use the normal [] style
# lookup and call attribute?()
def attribute?(attrib)
attributes.attribute?(attrib)
end
# Yield each key of the top level to the block.
def each(&block)
attributes.each(&block)
@override_runlist.reset!(args)
end
# Setter for override_runlist which allows setting an empty override run list and marking it to be used
#
# @params array [Array] override run list to set
# @return [Chef::RunList] the override run list
def override_runlist=(array)
@override_runlist_set = true
@override_runlist.reset!(array)
end
def select_run_list
override_runlist_set? ? @override_runlist : @primary_runlist
end
# Returns an Array of roles and recipes, in the order they will be applied.
# If you call it with arguments, they will become the new list of roles and recipes.
def run_list(*args)
rl = select_run_list
args.length > 0 ? rl.reset!(args) : rl
end
# Setter for override_runlist which allows setting an empty override run list and marking it to be used
#
# @params array [Array] override run list to set
# @return [Chef::RunList] the override run list
def override_runlist=(array)
@override_runlist_set = true
@override_runlist.reset!(array)
end
def select_run_list
override_runlist_set? ? @override_runlist : @primary_runlist
end
# Returns an Array of roles and recipes, in the order they will be applied.
# If you call it with arguments, they will become the new list of roles and recipes.
def run_list(*args)
rl = select_run_list
args.length > 0 ? rl.reset!(args) : rl
end
@missing_roles_with_including_role << [name, included_by]
@all_missing_roles[name] = true
nil
end
def errors
@missing_roles_with_including_role.map(&:first)
end
def to_json(*a)
Chef::JSONCompat.to_json(to_h, *a)
end
def to_h
seen_items = { recipe: {}, role: {} }
{ id: @environment, run_list: convert_run_list_trace("top level", seen_items) }
end
alias_method :to_hash, :to_h
private
On Mon, Aug 19, 2013 at 11:27 PM, Vladimir Skubriev <skubriev@cvisionlab.com
wrote:
$knife search node "recipes:cftp"
knife search node "hostname:zeus" -l | grep -C 10 recipes
metric: 256
proto: kernel
state: unknown
type: vnet
ohai_time: 1376978220.81941
os: linux
os_version: 3.5.0-34-generic
platform: ubuntu
platform_family: debian
platform_version: 12.04
recipes:
apt
ntp
cftp
cnfs::server
cinotify
nut
fail2ban
csquiddebproxy::server
csquiddebproxy
cbacula::client
OR other example:
knife search node "roles:ntp_server" -l | grep -C 10 roles
apt
ntp
cftp
cnfs::server
cinotify
nut
fail2ban
csquiddebproxy::server
csquiddebproxy
cbacula::client
roles:
ntp_server
nut_apcrt5000xl_serverroom_**server
uptime: 6 days 21 hours 09 minutes 00 seconds
uptime_seconds: 594540
virtualization:
role: host
system: kvm
What is the difference between roles and recipes attributes. Why with
recipes search are not work ?
Thank you very much.
--
Best regards,
CVisionLab System Administrator
Vladmir Skubriev
On Tue, Aug 20, 2013 at 2:27 AM, Vladimir Skubriev
skubriev@cvisionlab.com wrote:
What is the difference between roles and recipes attributes. Why with
recipes search are not work ?
In addition to Ranjib's explanation, there's documentation here:
Search indexes allow queries to be made for any type of data that is indexed by the Chef Infra Server, including data bags (and data bag items), environments, nodes, and roles.
Search indexes allow queries to be made for any type of data that is indexed by the Chef Infra Server, including data bags (and data bag items), environments, nodes, and roles.
Bryan