在EC2实例中,我如何将唯一的_if用于区域



我正在尝试设置一个唯一的食谱,我只希望在我们的东部区域中使用file1,而file2则在西部地区使用。目前的结果是,由于唯一的_if,客户端绕过食谱(文件)。我看了日志,但它们不是很有帮助。因此,对于为什么它不起作用,我感到失落。

我也以相同的负面结果尝试了这种方式。
节点[EC2] [plopement_availability_zone]

cookbook_file "/dir/dir/dir/file.json" do
only_if { node['ec2']['region'] == "us-east-1"}
  source "dir/file1.json"
  owner "user"
  group "group"
  action :create
  notifies :restart, "service[app-client]", :delayed
end
cookbook_file "/etc/dir/dir/file.json" do
only_if { node['ec2']['region'] == "us-west-2"}
  source "dir/file2.json"
  owner "user"
  group "group"
  action :create
  notifies :restart, "service[app-client]", :delayed
end

这是同一家服务器上的OHAI结果。

ohai | grep region
  "dm_region_hash": {
  "json?": "{n  "devpayProductCodes" : null,n  "privateIp" :        ”0.0.0.0”,n  "availabilityZone" : "us-west-2c",n  "version" : ”date”,n  "region" : "us-west-2",n  "instanceId" : ”ID”,n  "billingProducts" : null,n  "instanceType" : "t2.micro",n  "accountId" : "",n  "kernelId" : null,n  "ramdiskId" : null,n  "architecture" : "x86_64",n  "imageId" : ”ami-111111”,n  "pendingTime" : ”datetime”n}”,

因此,出于完全超出我的原因,您实际上无法通过EC2元数据系统获得该区域。您 can 获得可用性区,幸运的是,该地区总是只有AZ名称,最后一个字符被切断:

node['ec2']['placement_availability_zone'].chop

只是希望他们永远不会拥有超过26个AZ的地区,这应该可以正常工作。

最新更新