Seperated chef gems install to another function

This commit is contained in:
Avishai Ish-Shalom 2011-04-29 16:27:43 +03:00
parent ad408ecb90
commit 5c0a284ed2

View File

@ -32,22 +32,17 @@ def handle(name,cfg,cloud,log,args):
chef_cfg = cfg['chef'] chef_cfg = cfg['chef']
# Install chef packages from selected source # Install chef packages from selected source
if chef_cfg['install_type'] == "gems": if not os.path.isfile('/usr/bin/chef-client'):
ruby_version = util.get_cfg_option_str(chef_cfg, 'ruby_version', '1.8') if chef_cfg['install_type'] == "gems":
cc.install_packages(ruby_packages['ruby_version']) if chef_cfg.has_key('version'):
chef_version_arg = "" chef_version = chef_cfg['version']
if chef_cfg.has_key('version'): else:
chef_version_arg = '-v %s' % chef_cfg['version'] chef_version = None
subprocess.check_call([gem_bin,'install','chef',chef_version_arg, '--no-ri','--no-rdoc','--no-test','-q']) install_chef_from_gems(
os.mkdirs('/etc/chef', '/var/log/chef', '/var/lib/chef', '/var/cache/chef', '/var/backups/chef', '/var/run/chef') util.get_cfg_option_str(chef_cfg, 'ruby_version', '1.8'),
os.symlink('/var/lib/gem/%s/bin/chef-client' % ruby_version, '/usr/bin/chef-client') chef_version)
# Ohai ruby plugin breaks if there is no ruby or gem binaries at /usr/bin, so else:
try: os.symlink('/usr/bin/gem%s' % ruby_version, '/usr/bin/gem') cc.install_packages(('chef',))
except: pass
try: os.symlink('/usr/bin/ruby%s' % ruby_version, '/usr/bin/ruby')
except: pass
else:
cc.install_packages(('chef',))
# set the validation cert # set the validation cert
if chef_cfg.has_key('validation_cert'): if chef_cfg.has_key('validation_cert'):
@ -70,3 +65,16 @@ def handle(name,cfg,cloud,log,args):
# and finally, run chef # and finally, run chef
subprocess.check_call(['/usr/bin/chef-client'] + chef_args) subprocess.check_call(['/usr/bin/chef-client'] + chef_args)
def install_chef_from_gems(ruby_version, chef_version = None):
cc.install_packages(ruby_packages[ruby_version])
chef_version_arg = ""
if chef_version: chef_version_arg = "-v %s" % chef_version
subprocess.check_call([gem_bin,'install','chef',chef_version_arg, '--no-ri','--no-rdoc','--no-test','-q'])
os.mkdirs('/etc/chef', '/var/log/chef', '/var/lib/chef', '/var/cache/chef', '/var/backups/chef', '/var/run/chef')
os.symlink('/var/lib/gem/%s/bin/chef-client' % ruby_version, '/usr/bin/chef-client')
# Ohai ruby plugin breaks if there is no ruby or gem binaries at /usr/bin, so
try: os.symlink('/usr/bin/gem%s' % ruby_version, '/usr/bin/gem')
except: pass
try: os.symlink('/usr/bin/ruby%s' % ruby_version, '/usr/bin/ruby')
except: pass