{"id":1141,"date":"2009-11-09T00:19:12","date_gmt":"2009-11-08T23:19:12","guid":{"rendered":"http:\/\/www.devco.net\/?p=1141"},"modified":"2010-06-27T19:29:58","modified_gmt":"2010-06-27T18:29:58","slug":"rightscale_facts","status":"publish","type":"post","link":"https:\/\/www.devco.net\/archives\/2009\/11\/09\/rightscale_facts.php","title":{"rendered":"RightScale facts"},"content":{"rendered":"
I’m trying to build up a nice demo of mcollective and trying to save some effort by using the RightScale CentOS AMI’s.\u00a0 I noticed they came with a nice script to pull down the user data and meta data so figured I might as well make some facts.<\/p>\n
<\/code><\/p>\n If you arrange to run \/opt\/rightscale\/bin\/ec2.sh<\/em> in rc.local<\/em> and pop this fact above into your factdir you should be able to access all the meta data from facter.<\/p>\n <\/code><\/p>\n In addition if you just pass nice key=val<\/em> pairs in as user data it will add those as facts too, the last above is from that.<\/p>\n","protected":false},"excerpt":{"rendered":" I’m trying to build up a nice demo of mcollective and trying to save some effort by using the RightScale CentOS AMI’s.\u00a0 I noticed they came with a nice script to pull down the user data and meta data so figured I might as well make some facts. require ‘find’ if File.exists?(“\/var\/spool\/ec2\/meta-data”) Find.find(“\/var\/spool\/ec2\/meta-data”) do |path| […]<\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_et_pb_use_builder":"","_et_pb_old_content":"","footnotes":""},"categories":[1],"tags":[121,80,21,13],"_links":{"self":[{"href":"https:\/\/www.devco.net\/wp-json\/wp\/v2\/posts\/1141"}],"collection":[{"href":"https:\/\/www.devco.net\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.devco.net\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.devco.net\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/www.devco.net\/wp-json\/wp\/v2\/comments?post=1141"}],"version-history":[{"count":6,"href":"https:\/\/www.devco.net\/wp-json\/wp\/v2\/posts\/1141\/revisions"}],"predecessor-version":[{"id":1531,"href":"https:\/\/www.devco.net\/wp-json\/wp\/v2\/posts\/1141\/revisions\/1531"}],"wp:attachment":[{"href":"https:\/\/www.devco.net\/wp-json\/wp\/v2\/media?parent=1141"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.devco.net\/wp-json\/wp\/v2\/categories?post=1141"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.devco.net\/wp-json\/wp\/v2\/tags?post=1141"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}<\/p>\n
\r\nrequire 'find'\r\n\r\nif File.exists?(\"\/var\/spool\/ec2\/meta-data\")\r\n Find.find(\"\/var\/spool\/ec2\/meta-data\") do |path|\r\n filename = File.basename(path)\r\n factname = \"ec2_#{filename}\"\r\n\r\n factname.gsub!(\/-\/, \"_\")\r\n\r\n if File.file?(path)\r\n lines = File.readlines(path)\r\n\r\n if lines.size == 1\r\n Facter.add(factname) do\r\n setcode { lines.first.chomp.to_s }\r\n end\r\n else\r\n lines.each_with_index do |line, i|\r\n Facter.add(\"#{factname}_#{i}\") do\r\n setcode { lines[i].chomp }\r\n end\r\n end\r\n end\r\n end\r\n end\r\nend\r\n\r\nif File.exists?(\"\/var\/spool\/ec2\/user-data.raw\")\r\n lines = File.readlines(\"\/var\/spool\/ec2\/user-data.raw\")\r\n\r\n lines.each do |l|\r\n if l.chomp =~ \/(.+)=(.+)\/\r\n f = $1; v = $2\r\n\r\n Facter.add(f) do\r\n setcode { v }\r\n end\r\n end\r\n end\r\nend\r\n<\/pre>\n
<\/p>\n
\r\n# facter -p\r\nec2_ami_id => ami-73270c07\r\nec2_ami_launch_index => 0\r\nec2_ami_manifest_path => pinetecltd-centos-clustera\/cluster-webserver-1257783713.manifest.xml\r\nec2_ancestor_ami_ids_0 => ami-31c72258\r\nec2_ancestor_ami_ids_1 => ami-ef01e486\r\nec2_ancestor_ami_ids_2 => ami-0916f360\r\nec2_ancestor_ami_ids_3 => ami-c8ac48a1\r\nec2_ancestor_ami_ids_4 => ami-cd52b6a4\r\nec2_ancestor_ami_ids_5 => ami-19be966d\r\nec2_ancestor_ami_ids_6 => ami-65200b11\r\nec2_ancestor_ami_ids_7 => ami-3d200b49\r\nec2_ancestor_ami_ids_8 => ami-91200be5\r\nec2_ancestor_ami_ids_9 => ami-81200bf5\r\nec2_block_device_mapping_ami => sda1\r\nec2_block_device_mapping_ephemeral0 => sdb\r\nec2_block_device_mapping_ephemeral1 => sdc\r\nec2_block_device_mapping_ephemeral2 => sdd\r\nec2_block_device_mapping_ephemeral3 => sde\r\nec2_block_device_mapping_root => \/dev\/sda1\r\nec2_block_device_mapping_swap => sda3\r\nec2_hostname => ip-10-227-43-134.eu-west-1.compute.internal\r\nec2_instance_action => none\r\nec2_instance_id => i-9411e7e3\r\nec2_instance_type => m1.small\r\nec2_kernel_id => aki-7e0d250a\r\nec2_local_hostname => ip-10-227-43-134.eu-west-1.compute.internal\r\nec2_local_ipv4 => 10.227.43.134\r\nec2_placement_availability_zone => eu-west-1b\r\nec2_public_hostname => ec2-79-125-33-224.eu-west-1.compute.amazonaws.com\r\nec2_public_ipv4 => 79.125.33.224\r\nec2_public_keys_0_openssh_key => ssh-rsa AAA\r\nec2_ramdisk_id => ari-7d0d2509\r\nec2_reservation_id => r-c655bab1\r\nec2_security_groups_0 => rip\r\nec2_security_groups_1 => defaultcluster => a\r\n<\/pre>\n