Replace static dict mapping version to packages with a method (LP: #848932) Previously, there was a 'ruby_packages' dictionary that mapped the ruby version (1.8, 1.9, 1.9.1) to a list of packages that would need to be installed to get a functional gems. This replaces that with a method that is more likely to support future versions without requiring updates to cloud-init. It is not identical output as before. The changes are: * do not include 'ruby' in the case of 1.8, but rather 'ruby1.8' This is because the default could change, and 'ruby' would depend on a different default version. * do not explicitly list 'libruby-' as that is a dependenency of 'ruby' * End result is for any 'version' != 1.8, you'll get the following installed ruby ruby-dev === modified file 'cloudinit/CloudConfig/cc_chef.py' --- cloudinit/CloudConfig/cc_chef.py 2011-09-13 00:38:37 +0000 +++ cloudinit/CloudConfig/cc_chef.py 2011-09-13 12:22:42 +0000 @@ -24,9 +24,7 @@ import cloudinit.CloudConfig as cc import cloudinit.util as util -ruby_packages = {'1.8': ('ruby', 'rubygems', 'ruby-dev', 'libopenssl-ruby'), - '1.9.1': ('ruby1.9.1', 'ruby1.9.1-dev', 'libruby1.9.1'), - '1.9': ('ruby1.9', 'ruby1.9-dev', 'libruby1.9') } +ruby_version_default = "1.8" def handle(name,cfg,cloud,log,args): # If there isn't a chef key in the configuration don't do anything @@ -72,7 +70,8 @@ if install_type == "gems": # this will install and run the chef-client from gems chef_version = util.get_cfg_option_str(chef_cfg, 'version', None) - ruby_version = util.get_cfg_option_str(chef_cfg, 'ruby_version', '1.8') + ruby_version = util.get_cfg_option_str(chef_cfg, 'ruby_version', + ruby_version_default) install_chef_from_gems(ruby_version, chef_version) # and finally, run chef-client log.debug('running chef-client') @@ -81,8 +80,15 @@ # this will install and run the chef-client from packages cc.install_packages(('chef',)) +def get_ruby_packages(version): + # return a list of packages needed to install ruby at version + pkgs = [ 'ruby%s' % version, 'ruby%s-dev' % version ] + if version == "1.8": + pkgs.extend(('libopenssl-ruby1.8', 'rubygems1.8')) + return(pkgs) + def install_chef_from_gems(ruby_version, chef_version = None): - cc.install_packages(ruby_packages[ruby_version]) + cc.install_packages(get_ruby_packages(ruby_version)) if not os.path.exists('/usr/bin/gem'): os.symlink('/usr/bin/gem%s' % ruby_version, '/usr/bin/gem') if not os.path.exists('/usr/bin/ruby'):