Skip to content

Instantly share code, notes, and snippets.

@ccaum
Created August 19, 2011 21:57

Revisions

  1. ccaum created this gist Aug 19, 2011.
    39 changes: 39 additions & 0 deletions post-merge.rb
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,39 @@
    #!/usr/bin/env ruby

    require 'rubygems'
    require 'puppet'
    require 'puppet/face'
    require 'puppet/cloudpack'

    options = {
    :image => 'ami-3d76b754',
    :type => 'm1.large',
    :region => 'us-east-1',
    :keypair => 'ccaum_rsa',
    :keyfile => '/root/.ec2/ccaum_rsa.pem',
    :login => 'ec2-user'
    }

    #Fire up instance from AMI
    =begin
    server = Puppet::Face[:node, '0.0.1'].create :image => options[:image],
    :type => options[:type],
    :region => options[:region],
    :keypair => options[:keypair]
    Puppet::Face[:certificate, '0.0.1'].sign(certname)
    =end
    server = 'ec2-107-20-67-187.compute-1.amazonaws.com'

    #Run Puppet on Instance
    command = String.new
    unless options[:login] == 'root'
    command << '/usr/bin/sudo '
    end

    command << 'mkdir /tmp/testme'
    exit_code = Puppet::CloudPack.ssh_remote_execute(server, options[:login], command, options[:keyfile])

    raise "Failed to run puppet on instance #{server}" unless exit_code == 0

    puts "Successfully ran puppet on instance #{server}"