ruby - 厨师中的Grep curl elasticsearch输出
问题描述
我需要卷曲 elasticsearch 节点并在厨师中 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":{}}
但是当我尝试在厨师中使用它时,它只是忽略了它:
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
即使not_if
语句中的 curl 命令运行良好,厨师也会继续执行代码。
当我尝试 grep 仅“100”时,not_if 语句运行良好。因此,在我的情况下,grepping 多个字符串肯定存在问题"node_concurrent_recoveries":"100" .
知道如何在厨师中 grep 这个吗?
干杯
解决方案
您需要将 grep ( grep ''node_concurrent_recoveries'\:'100''
) 中的单引号替换为双引号,因为 json 中有双引号。您可以尝试使用 ruby % string literal,这样您就不需要转义很多引号。
not_if %Q(curl -u 'elastic:xxxxx' -XGET https://#{node['fqdn']}:9201/_cluster/settings | grep '"node_concurrent_recoveries":"100"' )
推荐阅读
- pascal - FreePascal / Lazarus 和实现 nsurlconnectiondatadelegate
- node.js - 更新 npm 版本时出错
- php - 找不到类“Maatwebsite\Excel\Excel”
- html - 确保用户在使用 Odoo html 表单构建器时在提交时选择下拉列表中的值
- xml - XSL 复制所有内容并替换
- android - 为背景操作栏设置渐变
- forms - 带有 BorderIcons 的无边框表单(如 Office 2016 应用程序)
- vue.js - 如何将 axios/axios 拦截器全局附加到 Nuxt?
- pandas - 如何提取列的唯一值及其计数并使用索引键存储在数据框中
- delphi - firemonkey 中带有样式书的透明表单