简体   繁体   English

如何使用Ruby in Chef标记EC2实例?

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

I'm playing around with Chef to launch EC2 instances. 我正在和Chef一起推出EC2实例。 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? 否则,实现这一目标的首选Ruby库是什么? 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社区食谱 - 假设您有关键信誉 - 如果您想以编程方式执行某些操作。

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. 通常,chef用于在实例上安装东西。 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 . 弄雾: gem install fog

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何使用 Ruby 从 EC2 实例获取特定标签值 - How do I get a specific tag value from an EC2 instance using Ruby 使用ruby SDK,如何获得针对我的AWS EC2实例签名的SSL证书? - Using the ruby SDK, how can I get an SSL certificate signed for my AWS EC2 instance? 如何在ruby中连接到EC2 Cassandra实例 - How to connect to an EC2 cassandra instance in ruby 如何判断我的机器是否为EC2实例? - How can I tell if my machine is an EC2 instance or not? 我正在尝试在RHEL6 ec2实例上安装Chef Server 11.x并使用gem安装刀并出现错误 - I am trying to install chef server 11.x on a RHEL6 ec2 instance and install knife using gem and getting error 无法访问使用ssh由ruby aws-sdk lib创建的ec2实例? - can't access ec2 instance which is created by ruby aws-sdk lib using ssh? 使用Ruby中的SCP / SSH和Amazon EC2实例中的pem文件 - Using SCP/SSH in Ruby with a pem file in an Amazon EC2 instance 如何使用ruby aws-sdk列出与ec2实例关联的所有卷ID? - How to list all volume-ids associated with ec2 instance using ruby aws-sdk? 如何使用 v2 ruby​​ sdk 为 ec2 实例分配 IP 地址 - how to assign an ip address to an ec2 instance using the v2 ruby sdk 如何使用RUBBER EC2 ruby​​ / rails部署工具指定数据库连接参数? - How do I specify database connection parameters using the RUBBER EC2 ruby / rails deployment tool?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM