Skip to content

Commit

Permalink
[KNIFE_EC2-3] Add --user-data to knife ec2 server create
Browse files Browse the repository at this point in the history
  • Loading branch information
schisamo committed Jul 30, 2011
1 parent 18078fa commit 0452396
Showing 1 changed file with 15 additions and 0 deletions.
15 changes: 15 additions & 0 deletions lib/chef/knife/ec2_server_create.rb
Expand Up @@ -141,6 +141,13 @@ class Ec2ServerCreate < Knife
:boolean => true,
:default => false

option :aws_user_data,
:long => "--user-data USER_DATA_FILE",
:short => "-u USER_DATA_FILE",
:description => "The EC2 User Data file to provision the instance with",
:proc => Proc.new { |m| Chef::Config[:knife][:aws_user_data] = m },
:default => nil

def tcp_test_ssh(hostname)
tcp_socket = TCPSocket.new(hostname, 22)
readable = IO.select([tcp_socket], nil, nil, 5)
Expand Down Expand Up @@ -180,6 +187,14 @@ def run
}
server_def[:subnet_id] = config[:subnet_id] if config[:subnet_id]

if Chef::Config[:knife][:aws_user_data]
begin
server_def.merge!(:user_data => File.read(Chef::Config[:knife][:aws_user_data]))
rescue
ui.warn("Cannot read #{Chef::Config[:knife][:aws_user_data]}: #{$!.inspect}. Ignoring option.")
end
end

if ami.root_device_type == "ebs"
ami_map = ami.block_device_mapping.first
ebs_size = begin
Expand Down

0 comments on commit 0452396

Please sign in to comment.