lib/chef/knife/ec2_server_create.rb in knife-ec2-0.14.0 vs lib/chef/knife/ec2_server_create.rb in knife-ec2-0.15.0
- old
+ new
@@ -252,11 +252,11 @@
:proc => Proc.new { |key| Chef::Config[:knife][:bootstrap_protocol] = key },
:default => nil
option :fqdn,
:long => "--fqdn FQDN",
- :description => "Pre-defined FQDN",
+ :description => "Pre-defined FQDN. This is used for Kerberos Authentication purpose only",
:proc => Proc.new { |key| Chef::Config[:knife][:fqdn] = key },
:default => nil
option :aws_user_data,
:long => "--user-data USER_DATA_FILE",
@@ -292,13 +292,13 @@
:boolean => true,
:default => false
option :ebs_volume_type,
:long => "--ebs-volume-type TYPE",
- :description => "Standard or Provisioned (io1) IOPS or General Purpose (gp2)",
+ :description => "Possible values are standard (magnetic) | io1 | gp2 | sc1 | st1. Default is gp2",
:proc => Proc.new { |key| Chef::Config[:knife][:ebs_volume_type] = key },
- :default => "standard"
+ :default => "gp2"
option :ebs_provisioned_iops,
:long => "--provisioned-iops IOPS",
:description => "IOPS rate, only used when ebs volume type is 'io1'",
:proc => Proc.new { |key| Chef::Config[:knife][:provisioned_iops] = key },
@@ -498,11 +498,15 @@
hashed_tags={}
tags.map{ |t| key,val=t.split('='); hashed_tags[key]=val} unless tags.nil?
# Always set the Name tag
unless hashed_tags.keys.include? "Name"
- hashed_tags["Name"] = locate_config_value(:chef_node_name) || @server.id
+ if locate_config_value(:chef_node_name)
+ hashed_tags["Name"] = evaluate_node_name(locate_config_value(:chef_node_name))
+ else
+ hashed_tags["Name"] = server.id
+ end
end
printed_tags = hashed_tags.map{ |tag, val| "#{tag}: #{val}" }.join(", ")
msg_pair("Instance ID", @server.id)
@@ -733,10 +737,11 @@
bootstrap.config[:bootstrap_curl_options] = locate_config_value(:bootstrap_curl_options)
bootstrap.config[:bootstrap_vault_file] = locate_config_value(:bootstrap_vault_file)
bootstrap.config[:bootstrap_vault_json] = locate_config_value(:bootstrap_vault_json)
bootstrap.config[:bootstrap_vault_item] = locate_config_value(:bootstrap_vault_item)
bootstrap.config[:use_sudo_password] = locate_config_value(:use_sudo_password)
+ bootstrap.config[:yes] = locate_config_value(:yes)
# Modify global configuration state to ensure hint gets set by
# knife-bootstrap
Chef::Config[:knife][:hints] ||= {}
Chef::Config[:knife][:hints]["ec2"] ||= {}
bootstrap
@@ -778,11 +783,16 @@
end
bootstrap.name_args = [fqdn]
bootstrap.config[:msi_url] = locate_config_value(:msi_url)
bootstrap.config[:install_as_service] = locate_config_value(:install_as_service)
bootstrap.config[:session_timeout] = locate_config_value(:session_timeout)
- bootstrap.config[:chef_node_name] = config[:chef_node_name] || server.id
+ bootstrap.config[:tags] = config[:tags]
+ if locate_config_value(:chef_node_name)
+ bootstrap.config[:chef_node_name] = evaluate_node_name(locate_config_value(:chef_node_name))
+ else
+ bootstrap.config[:chef_node_name] = server.id
+ end
bootstrap_common_params(bootstrap)
end
def bootstrap_for_linux_node(server,ssh_host)
bootstrap = Chef::Knife::Bootstrap.new
@@ -790,11 +800,16 @@
bootstrap.config[:ssh_user] = config[:ssh_user]
bootstrap.config[:ssh_password] = locate_config_value(:ssh_password)
bootstrap.config[:ssh_port] = config[:ssh_port]
bootstrap.config[:ssh_gateway] = config[:ssh_gateway]
bootstrap.config[:identity_file] = config[:identity_file]
- bootstrap.config[:chef_node_name] = locate_config_value(:chef_node_name) || server.id
+ bootstrap.config[:tags] = config[:tags]
+ if locate_config_value(:chef_node_name)
+ bootstrap.config[:chef_node_name] = evaluate_node_name(locate_config_value(:chef_node_name))
+ else
+ bootstrap.config[:chef_node_name] = server.id
+ end
bootstrap.config[:use_sudo] = true unless config[:ssh_user] == 'root'
# may be needed for vpc_mode
bootstrap.config[:host_key_verify] = config[:host_key_verify]
bootstrap_common_params(bootstrap)
end
@@ -970,10 +985,13 @@
}
If (winrm e winrm/config/listener | Select-String -Pattern " Transport = HTTP\\b" -Quiet) {
winrm delete winrm/config/listener?Address=*+Transport=HTTP
}
$vm_name = invoke-restmethod -uri http://169.254.169.254/latest/meta-data/public-ipv4
+If (-Not $vm_name) {
+ $vm_name = invoke-restmethod -uri http://169.254.169.254/latest/meta-data/local-ipv4
+}
New-SelfSignedCertificate -certstorelocation cert:\\localmachine\\my -dnsname $vm_name
$thumbprint = (Get-ChildItem -Path cert:\\localmachine\\my | Where-Object {$_.Subject -match "$vm_name"}).Thumbprint;
$create_listener_cmd = "winrm create winrm/config/Listener?Address=*+Transport=HTTPS '@{Hostname=`"$vm_name`";CertificateThumbprint=`"$thumbprint`"}'"
iex $create_listener_cmd
@@ -1214,22 +1232,26 @@
end
puts("done")
}
end
+ def subnet_public_ip_on_launch?
+ connection.subnets.get(server.subnet_id).map_public_ip_on_launch
+ end
+
def ssh_connect_host
unless @ssh_connect_host
if config[:server_connect_attribute]
connect_attribute = config[:server_connect_attribute]
+ server.send(config[:server_connect_attribute])
+ elsif vpc_mode? && !(subnet_public_ip_on_launch? || config[:associate_public_ip] || config[:associate_eip])
+ connect_attribute = "private_ip_address"
+ server.private_ip_address
else
- if vpc_mode? && !(config[:associate_public_ip] || config[:associate_eip])
- connect_attribute = "private_ip_address"
- else
- connect_attribute = server.dns_name ? "dns_name" : "public_ip_address"
- end
+ connect_attribute = server.dns_name ? "dns_name" : "public_ip_address"
+ server.send(connect_attribute)
end
-
@ssh_connect_host = server.send(connect_attribute)
end
puts "\nSSH Target Address: #{@ssh_connect_host}(#{connect_attribute})"
@ssh_connect_host
@@ -1379,10 +1401,11 @@
password = private_key.private_decrypt(encrypted_password)
password
end
def check_windows_password_available(server_id)
+ sleep 10
response = connection.get_password_data(server_id)
if not response.body["passwordData"]
return false
end
response.body["passwordData"]
@@ -1391,11 +1414,10 @@
def windows_password
if not locate_config_value(:winrm_password)
if locate_config_value(:identity_file)
print "\n#{ui.color("Waiting for Windows Admin password to be available", :magenta)}"
print(".") until check_windows_password_available(@server.id) {
- sleep 1000 #typically is available after 30 mins
puts("done")
}
response = connection.get_password_data(@server.id)
data = File.read(locate_config_value(:identity_file))
config[:winrm_password] = decrypt_admin_password(response.body["passwordData"], data)
@@ -1413,8 +1435,15 @@
require 'chef/knife/winrm'
require 'chef/knife/bootstrap_windows_winrm'
require 'chef/knife/bootstrap_windows_ssh'
require 'chef/knife/core/windows_bootstrap_context'
end
+
+ #Returns the name of node after evaluation of server id if %s is present.
+ #Eg: "Test-%s" will return "Test-i-12345" in case the instance id is i-12345
+ def evaluate_node_name(node_name)
+ return node_name%server.id
+ end
+
end
end
end