簡體   English   中英

如何在EC2實例中的地區使用only_if

[英]How do I use the only_if for regions in EC2 instances

我正在嘗試設置only_if配方,我只希望在東部地區使用file1,在西部地區使用File2。 現在的結果是,由於only_if,客戶端繞過了食譜(文件)。 我看了一下日志,但它們的內容不是很豐富。 所以我迷茫的為什么它不起作用。

我也嘗試過這種方法,但結果相同。
節點[ec2] [placement_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\" : \”date\time\”\n}”,

因此,出於我完全無法理解的原因,您實際上無法通過EC2元數據系統獲得該區域。 可以獲取可用區域,幸運的是,該區域始終只是最后一個字符被切掉的AZ名稱:

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

只是希望他們永遠不要使一個區域具有超過26個可用區,並且應該可以正常工作。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM