简体   繁体   中英

How can I tag an EC2 instance using Ruby in Chef?

I'm playing around with Chef to launch EC2 instances. Everything is working pretty well, but Chef doesn't seem to have the ability to tag the instances. Am I missing something?

Otherwise, what's the preferred Ruby library for achieving this? Can I do it without requiring additional gems?

Thanks

knife-ec2 -ec2 Gem版本0.5.12支持使用--tags选项在创建时标记EC2实例。

knife ec2 server create [... your options...] --tags Tag=Value

Know this is old, but was browsing about and spotted it. Another alternative is to use the AWS community cookbook - assuming you have key creds - if you want to do things programatically as part of the recipe.

aws = data_bag_item('mydatabag', 'creds')
aws_resource_tag node['ec2']['instance_id'] do
  aws_access_key aws['access_key']
  aws_secret_access_key aws['secret_key']
  tags({
    "foo" => "bar"
  })
  action :update
end

Usually chef is used to install things on the instance. I'm not exactly sure how you start a node with chef, but maybe you can share this and I'll extend my answer?

Otherwise, fog is a great library to do these things. I just skimmed over the source and it seems to support tagging as well.

To get fog: gem install fog .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM