尝试在节点上搜索具有指定cookbook和配方的节点,但它显示以下错误:
================================================================================
Recipe Compile Error in /var/chef/cache/cookbooks/lbsvc/recipes/default.rb
================================================================================
Net::HTTPServerException
------------------------
400 "Bad Request"
...
Relevant File Content:
----------------------
/var/chef/cache/cookbooks/lbsvc/recipes/loadbalancer.rb:
12: template "/etc/haproxy/haproxy.cfg" do
13: source "haproxy.cfg.erb"
14: owner "haproxy"
15: group "haproxy"
16: variables({
17: gw_nodes: search(:node, "chef_environment:#{node.chef_environment} AND recipe:realdoc-gateway").sort_by{ |n| n.name },
18>> microservice_nodes: search(:node, "chef_environment:#{node.chef_environment} AND recipes:'microservice::loadbalancer'").sort_by{ |n| n.name },
19: microservice2_nodes: search(:node, "chef_environment:#{node.chef_environment} AND recipes:'microservice2::loadbalancer'").sort_by{ |n| n.name },
20: ui_nodes: search(:node, "chef_environment:#{node.chef_environment} AND recipe:vault-ui").sort_by{ |n| n.name }
21: })
22: notifies :reload, 'service[haproxy]'
23: end
Running handlers:
[2016-09-04T13:30:26+00:00] ERROR: Running exception handlers
Running handlers complete
[2016-09-04T13:30:26+00:00] ERROR: Exception handlers complete
[2016-09-04T13:30:26+00:00] FATAL: Stacktrace dumped to /var/chef/cache/chef-stacktrace.out
Chef Client failed. 0 resources updated in 5.477354028 seconds
[2016-09-04T13:30:26+00:00] ERROR: 400 "Bad Request"
[2016-09-04T13:30:26+00:00] FATAL: Chef::Exceptions::ChildConvergeError: Chef run process exited unsuccessfully (exit code 1)
它在recipes:microservice\:\:loadbalancer
显示错误,即使我从chefdocs获得语法,我也不能正确使用它。
答案 0 :(得分:3)
使用双引号("
)时,必须双重转义(\\
)冒号:
search(:node, "recipes:microservice\\:\\:loadbalancer")
使用单引号时,只需一次反斜杠即可。
search(:node, 'recipes:microservice\:\:loadbalancer')