Purpose: Use Cfengine to automatically provision VM's on Amazon EC2. I've chosen the Amazon command line tools suite (ec2-run-instances, ec2-describe-instances, ec2-terminate-instances, etc.). I was considering using the Perl Net::Amazon::EC2 library but the author is still in the process of adding support for Amazon's relatively new "micro" instances, which is what I prefer to use because they are cheaper.
The below works but I'd love to port the shell script to Cfengine. (Patches welcome if you have time and interest.) Here is my little helper script that I use to provision a "micro" instances using an Ubuntu 10.04 AMI; it returns the instance ID and public hostname. It's good enough for now, I've got a multi-node orchestration demo Saturday, and I'm only 1/3 done. (provisioning, configuration, integration) :::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::: start_micro_instance.sh :::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::: #!/bin/sh INSTANCE_ID=`ec2-run-instances -t t1.micro ami-6c06f305 -k mysshkey 2>&1 | awk '/^INSTANCE/ {print $2}'` sleep 2 INSTANCE_HOSTNAME=pending while [ "${INSTANCE_HOSTNAME}" = "pending" ] do sleep 3 INSTANCE_HOSTNAME=`ec2-describe-instances $INSTANCE_ID | awk '/^INSTANCE/ {print $4}'` done echo $INSTANCE_ID $INSTANCE_HOSTNAME :::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::: And here is the Cfengine promises that will provision N servers, and save their instance id's and public hostnames into little text file in "servers" directory - we want the hostnames so we can install Orion Cloud Packs, and id's so that we can terminate the instances when we are done. Best, -at body common control { bundlesequence => { "servers_provisioned", }; inputs => { "/var/cfengine/inputs/cfengine_stdlib.cf" }; } ############################################# bundle agent servers_provisioned { vars: "desired_servers" slist => { "haproxy", "web1", "web2", }; classes: "$(desired_servers)_up" expression => fileexists("/home/user/cfengine_ec2/servers/$(desired_servers)"); "$(desired_servers)_down" not => fileexists("/home/user/cfengine_ec2/servers/$(desired_servers)"); reports: "$(desired_servers) has been provisioned" ifvarclass => canonify("$(desired_servers)_up"); commands: "/home/user/cfengine_ec2/start_micro_instance.sh $(desired_servers) > /home/user/cfengine_ec2/servers/$(desired_servers)" ifvarclass => canonify("$(desired_servers)_down"), contain => in_shell; } _______________________________________________ Help-cfengine mailing list Help-cfengine@cfengine.org https://cfengine.org/mailman/listinfo/help-cfengine