<\/p>\n\r\nnewaction(\"shell\") do |cmd, ud, md, config|\r\n if cmd.include?(:command)\r\n system(cmd[:command])\r\n end\r\nend\r\n<\/pre>\n<\/code><\/p>\n
You want to host this on any webserver in a file called shell.rb<\/em>. Now create a file list.txt<\/em> in the same location that just have this:<\/p>\n<\/p>\n\r\nshell.rb\r\n<\/pre>\n<\/code><\/p>\n
You can list as many scripts as you want. Now when you boot your instance pass it data like this:<\/p>\n
<\/p>\n\r\n--- \r\n:facts: \r\n role: webserver\r\n:actions: \r\n- :url: http:\/\/your.net\/path\/to\/actions\/list.txt\r\n :type: :getactions\r\n- :type: :shell\r\n :command: date > \/tmp\/test\r\n<\/pre>\n<\/code><\/p>\n
The above will fetch the list of actions – our shell.rb<\/em> – from http:\/\/your.net\/path\/to\/actions\/list.txt<\/em> and then run using the shell<\/em> action the command date > \/tmp\/test<\/em>. The actions are run in order so you probably always want getactions<\/em> to happen first.<\/p>\nOther actions that this script will take:<\/p>\n
\n- Cache all the user and meta data in \/var\/spool\/ec2boot<\/em><\/li>\n
- Create \/etc\/facts.txt<\/em> with all your facts that you passed in as well as a flat version of the entire instance meta data<\/em>. <\/li>\n
- Create a MOTD that shows some key data like AMI ID, Zone, Public and Private hostnames<\/li>\n<\/ul>\n
The boot library provides a few helpers that help you write scripts for this environment specifically around fetching files and logging:<\/p>\n
<\/p>\n\r\n [\"rubygems-1.3.1-1.el5.noarch.rpm\",\r\n \"rubygem-stomp-1.1.6-1.el5.noarch.rpm\",\r\n \"mcollective-common-#{version}.el5.noarch.rpm\",\r\n \"mcollective-#{version}.el5.noarch.rpm\",\r\n \"server.cfg.templ\"].each do |pkg|\r\n EC2Boot::Util.log(\"Fetching pkg #{pkg}\")\r\n EC2Boot::Util.get_url(\"http:\/\/foo.s3.amazonaws.com\/#{pkg}\", \"\/mnt\/#{pkg}\")\r\n end\r\n<\/pre>\n<\/code><\/p>\n
This code fetches a bunch of files from a S3 bucket and save them into \/mnt<\/em>. Each one gets logged to console and syslog. Using this GET helper has the advantage that it has sane retrying etc built in for you already.<\/p>\nIt’s fairly early days for this code but it works and I am using it, I’ll probably be adding a few more features soon, let me know in comments if you need anything specific or even if you find it useful.<\/p>\n","protected":false},"excerpt":{"rendered":"
I’ve been working a bit on streamlining the builds I do on EC2 and wanted a better way to provision my machines. I use CentOS and things are pretty rough to non existent for nicely built EC2 images. I’ve used the Rightscale ones till now and while they’re nice they are also full of lots […]<\/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":[88,87,121,13],"_links":{"self":[{"href":"https:\/\/www.devco.net\/wp-json\/wp\/v2\/posts\/1580"}],"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=1580"}],"version-history":[{"count":11,"href":"https:\/\/www.devco.net\/wp-json\/wp\/v2\/posts\/1580\/revisions"}],"predecessor-version":[{"id":1590,"href":"https:\/\/www.devco.net\/wp-json\/wp\/v2\/posts\/1580\/revisions\/1590"}],"wp:attachment":[{"href":"https:\/\/www.devco.net\/wp-json\/wp\/v2\/media?parent=1580"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.devco.net\/wp-json\/wp\/v2\/categories?post=1580"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.devco.net\/wp-json\/wp\/v2\/tags?post=1580"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}