Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Support for new config parameter: 'root'; fixes related to ubuntu and…

… ssh
  • Loading branch information...
commit 23565615350b46cafe5247105af7fd76f5064151 1 parent a8d82a5
@delano delano authored
View
7 Rudyfile
@@ -72,6 +72,12 @@ machines do
#end
end
+ role :ubuntu do
+ ami 'ami-1a837773'
+ root 'ubuntu'
+ user 'ubuntu'
+ end
+
end
end
@@ -181,6 +187,7 @@ defaults do
environment :stage
role :app
color true # Terminal colors? true/false
+ #root 'rootuser' # The "root" account (on Ubuntu, set to "ubuntu")
#user 'someuser' # The default remote user
#localhost 'hostname' # A local hostname instead of localhost
#auto true # Skip interactive confirmation?
View
8 lib/rudy/cli/machines.rb
@@ -153,8 +153,8 @@ def disassociate_machines
def update_machines
mlist = get_machines
- rset = Rye::Set.new(current_group_name, :parallel => @@global.parallel, :user => default_user)
- rset.add_key user_keypairpath(default_user)
+ rset = Rye::Set.new(current_group_name, :parallel => @@global.parallel, :user => current_machine_root)
+ rset.add_key user_keypairpath(current_machine_root)
os = current_machine_os
mlist.each do |m|
li "Updating #{m.name}"
@@ -199,7 +199,7 @@ def ssh_valid?
end
def ssh
-
+
# TODO: Give this method a good look over
pkey = current_user_keypairpath
@@ -275,7 +275,7 @@ def ssh
# Make sure we want to run this command on all instances
if !checked && command != :interactive_ssh
- execute_check(:low) if rye_opts[:user] == "root"
+ execute_check(:low) if current_machine_user == "root"
checked = true
end
View
34 lib/rudy/huxtable.rb
@@ -1,4 +1,4 @@
-
+
module Rudy
@@ -81,10 +81,23 @@ def config_dirname
base_dir
end
+ def default_root
+ (@@config.defaults.root || 'root').to_s
+ end
+
def default_user
- @@config.defaults.user.to_s || 'root'
+ (@@config.defaults.user || current_machine_root).to_s
+ end
+
+ def current_machine_root
+ (fetch_machine_param(:root) || default_root).to_s
+ end
+
+ def current_machine_user
+ (@@global.user || fetch_machine_param(:user) || default_user || Rudy.sysinfo.user).to_s
end
+
# Returns the name of the current keypair for the given user.
# If there's a private key path in the config this will return
# the basename (it's assumed the Amazon Keypair has the same
@@ -97,17 +110,22 @@ def user_keypairname(user=nil)
if path
Huxtable.keypair_path_to_name(path)
else
- n = (user.to_s == default_user) ? '' : "-#{user}"
+ n = current_user_is_root?(user) ? '' : "-#{user}"
"key-%s-%s%s" % [@@global.zone, current_machine_group, n]
end
end
def root_keypairname
- user_keypairname :root
+ user_keypairname current_machine_root
end
def current_user_keypairname
user_keypairname current_machine_user
end
+ def current_user_is_root?(user=nil)
+ user ||= current_machine_user
+ user.to_s == current_machine_root
+ end
+
def user_keypairpath(name=nil)
name ||= current_machine_user
path = defined_keypairpath name
@@ -123,7 +141,7 @@ def user_keypairpath(name=nil)
path
end
def root_keypairpath
- user_keypairpath :root
+ user_keypairpath current_machine_root
end
def current_user_keypairpath
user_keypairpath current_machine_user
@@ -197,11 +215,7 @@ def current_machine_address(position='01')
def current_machine_name
[@@global.zone, current_machine_group, @@global.position].join(Rudy::DELIM)
end
-
- def current_machine_user
- @@global.user || fetch_machine_param(:user) || default_user || Rudy.sysinfo.user
- end
-
+
def current_machine_bucket
@@global.bucket || fetch_machine_param(:bucket) || nil
end
View
3  lib/rudy/routines/handlers/host.rb
@@ -95,12 +95,11 @@ def set_hostname(rset)
# NOTE: This will set hostname every time a routine is
# run so we may want to make this an explicit action.
hntype = current_machine_hostname || :rudy
- this_default_user = default_user
return if hntype.to_s.to_sym == :default
rset.batch do
unless self.stash.os == :windows
hn = hntype == :rudy ? self.stash.name : hntype
- if self.user.to_s == this_default_user
+ if self.user.to_s == 'root' # ubuntu has a root user
hostname hn
else
sudo do
View
24 lib/rudy/routines/handlers/keypair.rb
@@ -7,7 +7,8 @@ module Keypair
##Rudy::Routines.add_handler :machines, self
- def raise_early_exceptions(name=:root)
+ def raise_early_exceptions(name=nil)
+ name ||= current_machine_root
keyname = user_keypairname name
kp_file = pkey name
if registered? keyname
@@ -20,7 +21,8 @@ def raise_early_exceptions(name=:root)
end
end
- def create(name=:root)
+ def create(name=nil)
+ name ||= current_machine_root
keyname = user_keypairname name
kp_file = pkey name
@@ -53,32 +55,38 @@ def create(name=:root)
kp
end
- def unregister(name=:root)
+ def unregister(name=nil)
+ name ||= current_machine_root
keyname = user_keypairname name
raise "Keypair not registered: #{keyname}" unless registered?(name)
Rudy::AWS::EC2::Keypairs.destroy keyname
end
- def delete_pkey(name=:root)
+ def delete_pkey(name=nil)
+ name ||= current_machine_root
kp_file = pkey name
raise PrivateKeyNotFound, kp_file unless pkey?(name)
File.unlink kp_file
end
- def exists?(name=:root)
+ def exists?(name=nil)
+ name ||= current_machine_root
registered?(name) && pkey?(name)
end
- def registered?(name=:root)
+ def registered?(name=nil)
+ name ||= current_machine_root
keyname = user_keypairname name
Rudy::AWS::EC2::Keypairs.exists?(keyname)
end
- def pkey(name=:root)
+ def pkey(name=nil)
+ name ||= current_machine_root
user_keypairpath name
end
- def pkey?(name=:root)
+ def pkey?(name=nil)
+ name ||= current_machine_root
File.exists? pkey(name)
end
View
5 lib/rudy/routines/handlers/rye.rb
@@ -17,7 +17,8 @@ def create_box(hostname, opts={})
:user => current_machine_user,
:ostype => current_machine_os || :unix,
:impltype => :linux,
- :info => STDOUT
+ :info => STDOUT,
+ :paranoid => false # doesn't get passed through (Rye bug?)
}.merge opts
nickname = hostname
@@ -80,7 +81,7 @@ def create_set(hostnames, opts={})
:quiet => Rudy.quiet?
}.merge(opts)
set = ::Rye::Set.new current_machine_group, opts
-
+
opts.delete(:parallel) # Not used by Rye::Box.new
hostnames.each do |m|
View
2  lib/rudy/routines/shutdown.rb
@@ -83,7 +83,7 @@ def raise_early_exceptions
## it prevents shutting down.
# Check private key after machine group, otherwise we could get an error
# about there being no key which doesn't make sense if the group isn't running.
- ##raise Rudy::PrivateKeyNotFound, root_keypairpath unless has_keypair?(:root)
+ ##raise Rudy::PrivateKeyNotFound, root_keypairpath unless has_keypair?(current_machine_root)
if @routine
bad = @routine.keys - @@allowed_actions
raise UnsupportedActions.new(@name, bad) unless bad.empty?
Please sign in to comment.
Something went wrong with that request. Please try again.