我有一个配置 ec2 实例的方法,我试图将环境应用到该实例,我运行如下:
chef-client -z -o 'myapp::dev_create'
default.rb 属性文件定义为:
default['myapp_provisioner'].tap do |myapp_provisioner|
myapp_provisioner['node_name'] = 'test'
end
myapp::dev_create 配方定义为:
require 'chef/provisioning'
Chef::Config.chef_provisioning({
:machine_max_wait_time => 240
})
# Override environment specific configs
node.override['myapp_provisioner']['node_name'] = 'RULZ_DEV'
include_recipe 'myapp_provisioner::ec2_instance' # sets machine_options
# The line below prints "RULZ_DEV"
# as it is overridden above
puts node['myapp_provisioner']['node_name']
machine node['myapp_provisioner']['node_name'] do
chef_environment 'DEV'
admin true # run as sudo
recipe 'myapp::copy_tls_certs'
role 'reverse_proxy'
role 'app_server'
end
配方 myapp::copy_tls_certs 定义为:
node_name = node['myapp_provisioner']['node_name']
# The line below prints the value from default attributes "test"
puts "cert path ---------------> #{node_name}"
更新
我之前将这个问题命名为Chef Environment not overriding recipe called inside a machine resource
,但我开始意识到这个问题与环境无关,而只是关于在机器资源中覆盖和使用这些属性的属性。感觉就像我在这里遗漏了一些非常基本的东西,有什么想法吗?