gpt4 book ai didi

ruby - 我将如何在 Chef Recipe 中包含和配置 ruby​​ 库?

转载 作者:数据小太阳 更新时间:2023-10-29 08:02:51 26 4
gpt4 key购买 nike

我想在我的 Chef Recipe 中包含 Diplomat gem,以便我可以在 .erb 模板中执行 Consul 变量查找。

我需要配置 Consul URL:

irb(main):015:0> require 'diplomat'
irb(main):016:0> Diplomat.configure do |config|
irb(main):017:1* config.url = "consulurl:80"
irb(main):018:1> end

设置一个变量作为 URL 路径:

irb(main):020:0> kv_path = "path/to/variable"
=> "path/to/variable"

最后,在模板中执行查找。

irb(main):022:0> foo = Diplomat::Kv.get(kv_path + '/test_foo_123')
=> "bar"

我需要在说明书的什么地方编写上面的配置代码,以便我可以在 .erb 模板中执行变量查找?

最佳答案

您想使用chef_gem 资源,但要确保在编译阶段运行它:

chef_gem 'diplomat' do
action :nothing
compile_time false
end.run_action(:install)
require 'diplomat'

关于ruby - 我将如何在 Chef Recipe 中包含和配置 ruby​​ 库?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39755314/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com