【发布时间】:2014-01-14 15:36:52
【问题描述】:
我正在尝试使用knife-solo 设置几个服务器,并且我需要在配方中使用基本搜索,这样我才能知道哪些服务器正在执行特定的角色。这似乎是使用搜索的最基本目的。
我正在使用 chef-solo-search,但是我无法按照文档中描述的(似乎是)按角色查找节点;我完全被难住了。我可以破解一个解决方案,但似乎我做错了什么。我构建了一个简化的示例来演示我的问题。
这不起作用...
我创建了一个虚拟角色roles/test_role.json
{
"name": "test_role",
"default_attributes": {},
"json_class": "Chef::Role",
"run_list": [],
"description": "",
"override_attributes": {}
}
我测试搜索具有“test_role”角色的节点的基本方法: site-cookbooks/nodesearch/recipes/default.rb
# required for search with knife-solo
include_recipe "chef-solo-search"
# this is now the test code for chef-solo-search shows to search for nodes that implement a role.
# see https://github.com/edelight/chef-solo-search/blob/master/tests/test_search.rb ~ line 208
nodes = search(:node, "role:test_role")
# This creates a line for each node found in the search...
search_content = nodes.map {|node| "id: #{node['id']} run_list: #{node['run_list']}\n"}.join
# And writes it to a file
file "/var/test_role_nodes.txt" do
content search_content
action :create
end
我已经创建了两个节点:
nodes/node1.json
{
"id": "node1",
"run_list": ["recipe[nodesearch]"]
}
nodes/node2.json
{
"id": "node2",
"run_list": ["role[test_role]"]
}
当我“烹饪”node1(运行 nodesearch 配方)时,我期待 search(:node, "role:test_role") 搜索找到 node2,但它什么也没返回。我尝试将节点定义移动到 data_bags 目录 因为文档(在某些地方)似乎暗示这是必要的,我已经尝试了各种 具有 solo.rb 设置等的恶作剧。我相信我已经按照文档说明设置了 chef-solo-search,并且我没有收到任何错误指示。没有想法。
但这行得通...
我所做的唯一有效的事情是:重写搜索配方:
nodes = search(:node, "role:test_role")
到这里:
nodes = search(:node, "run_list:*role\\[test_role\\]*")
第二种形式实际上得到了我想要的结果。这是一个可以接受的解决方法,但它似乎有点像黑客,这让我想知道...... 要么我一定是做错了什么,要么刀独奏和厨师独奏搜索的所有文档都是 错误(这似乎不太可能!)
谁能帮助解释为什么我无法使用 search(:node, "role:test_role") 获得任何搜索结果??
(出于许多仔细考虑的原因,我们明确选择不使用厨师服务器解决方案。)
【问题讨论】:
标签: chef-infra chef-solo knife-solo