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

I play with a chef to launch EC2 instances. Everything works very well, but the chef has no way to mark instances. Did I miss something?

Otherwise, what is the Ruby library for this purpose? Can I do this without requiring additional stones?

thanks

+6
source share
3 answers

Version 0.5.12 knife-ec2 Gem supports tagging EC2 instances when created using the --tags .

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

Know that it is old, but looked through and noticed. Another alternative is to use the AWS community cookbook - if you have key loans - if you want to do something programmatically as part of a 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 
+2
source

Usually a chef is used to set things up in an instance. I'm not quite sure how you start node with a chef, but maybe you can share this and I will continue my answer?

Otherwise, fog is a great library to perform these tasks. I was just browsing the source, and it looks like it also supports tagging.

To get the fog: gem install fog .

0
source

Source: https://habr.com/ru/post/888679/


All Articles