New Relic基础设施Agent安装报错:缺少NewRelic密钥求助
解决New Relic基础设施Agent Chef Cookbook安装时的密钥缺失问题
从你提供的报错信息和Recipe代码来看,核心问题是在newrelic::infrastructure_agent Recipe执行时,node['newrelic']['license']属性还没被正确设置,导致Cookbook的校验逻辑触发了RuntimeError: The NewRelic key is required错误。
问题根源分析
你当前的Recipe执行顺序出了问题:
- 先引入了
newrelic::infrastructure_agentRecipe - 之后才赋值
node.normal['newrelic']['license']属性
Chef是按Recipe的代码顺序逐行执行的,当newrelic::infrastructure_agent里的newrelic_agent_infrastructure 'Install'资源运行时,你的密钥还没被赋值,自然会触发校验失败。
修复方案
调整代码顺序,先设置密钥属性,再引入New Relic的Recipe:
# Cookbook:: third-party-newrelic # Recipe:: infraestructure-agent # Copyright:: 2018, The Authors, All Rights Reserved. include_recipe 'base::databag' # 优先加载并设置New Relic密钥属性 newrelic = decrypt_databag('newrelic') node.normal['newrelic']['license'] = newrelic['license_key'] # 再引入New Relic的基础设施Agent Recipe include_recipe 'newrelic::infrastructure_agent'
额外排查建议
如果调整顺序后仍有问题,可以做以下验证:
- 确认
decrypt_databag('newrelic')确实能返回包含有效license_key的数据 - 在引入New Relic Recipe前,临时添加日志输出验证属性是否生效:
Chef::Log.info("当前New Relic密钥值: #{node['newrelic']['license']}") - 如果你用
node.default_unless设置密钥,检查是否有更高优先级的属性(比如环境、角色属性)覆盖了这个值
内容的提问来源于stack exchange,提问作者Daniel
相关产品推荐
相关产品推荐

