Class: Chef::Knife::ServerBootstrapEc2

Inherits:
Chef::Knife show all
Includes:
ServerBootstrapBase
Defined in:
lib/chef/knife/server_bootstrap_ec2.rb

Overview

Provisions an EC2 instance and sets up an Open Source Chef Server.

Instance Method Summary collapse

Methods included from ServerBootstrapBase

included

Instance Method Details

#ec2_bootstrapObject



71
72
73
74
75
76
77
78
79
80
81
82
83
# File 'lib/chef/knife/server_bootstrap_ec2.rb', line 71

def ec2_bootstrap
  setup_environment
  bootstrap = Chef::Knife::Ec2ServerCreate.new
  Chef::Knife::Ec2ServerCreate.options.keys.each do |attr|
    val = config_val(attr)
    next if val.nil?

    bootstrap.config[attr] = val
  end
  bootstrap.config[:tags] = bootstrap_tags
  bootstrap.config[:distro] = bootstrap_distro
  bootstrap
end

#ec2_connectionObject



85
86
87
88
89
90
91
92
# File 'lib/chef/knife/server_bootstrap_ec2.rb', line 85

def ec2_connection
  @ec2_connection ||= Fog::Compute.new(
    :provider => "AWS",
    :aws_access_key_id => config_val(:aws_access_key_id),
    :aws_secret_access_key => config_val(:aws_secret_access_key),
    :region => config_val(:region)
  )
end

#runObject



62
63
64
65
66
67
68
69
# File 'lib/chef/knife/server_bootstrap_ec2.rb', line 62

def run
  super
  config_security_group
  ec2_bootstrap.run
  fetch_validation_key
  create_root_client
  install_client_key
end

#server_dns_nameObject



94
95
96
97
98
99
100
101
102
# File 'lib/chef/knife/server_bootstrap_ec2.rb', line 94

def server_dns_name
  server = ec2_connection.servers.find do |s|
    s.state == "running" &&
      s.tags["Name"] == config_val(:chef_node_name) &&
      s.tags["Role"] == "chef_server"
  end

  server && server.dns_name
end