Grep curl elasticsearch 在 chef 中的输出。

问题描述 投票:1回答:1

我需要卷曲elasticsearch节点并在chef中grep结果。

当我试着在盒子上手动操作时,它工作得很好--高亮地显示我需要的东西。

curl -u 'elastic:xxxxxx' -XGET https://x.x.x.x:9201/_cluster/settings | grep '"node_concurrent_recoveries"\:"100"'
  % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                 Dload  Upload   Total   Spent    Left  Speed
100   141  100   141    0     0  14100      0 --:--:-- --:--:-- --:--:-- 14100
{"persistent":{"cluster":{"routing":{"allocation":{"cluster_concurrent_rebalance":"55","node_concurrent_recoveries":"100"}}}},"transient":{}}

但当我试图在chef中使用它时,它就会忽略它。

 bash 'set-concurrent-restores-to-100' do
    user 'root'
    code <<-EOC
    echo "setting concurrent restores to 100..."
    curl -u 'elastic:#{node['ElasticPassword']}' -XPUT -H 'Content-Type: application/json' 'https://#{node['fqdn']}:9201/_cluster/settings' -d '{ "persistent": { "cluster.routing.allocation.node_concurrent_recoveries": "100" } }'
    EOC
    not_if "curl -u 'elastic:xxxxx' -XGET https://#{node['fqdn']}:9201/_cluster/settings | grep ''node_concurrent_recoveries'\:'100'' "
  end

chef一直在执行代码,即使curl命令在... not_if 语句工作良好。

当我尝试只grep "100 "时,not_if语句工作正常。所以在我的例子中,grep不止一个字符串肯定是有问题的。"node_concurrent_recoveries":"100" .

知道如何在chef中grep这个吗?

欢呼

ruby bash elasticsearch chef
1个回答
2
投票

你需要在grep中替换你的单引号(grep ''node_concurrent_recoveries'\:'100'')加双引号,因为你在json中有双引号。你可以尝试使用ruby % 字符串,这样你就不需要逃避很多的行情。

not_if %Q(curl -u 'elastic:xxxxx' -XGET https://#{node['fqdn']}:9201/_cluster/settings | grep '"node_concurrent_recoveries":"100"' )
© www.soinside.com 2019 - 2024. All rights reserved.