diff options
author | Avishai Ish-Shalom <avishai.ish-shalom@mail.huji.ac.il> | 2011-04-29 16:27:43 +0300 |
---|---|---|
committer | Avishai Ish-Shalom <avishai.ish-shalom@mail.huji.ac.il> | 2011-04-29 16:27:43 +0300 |
commit | 5682ecb6649f65173a92d80e024e32e7d1cf7359 (patch) | |
tree | 5d4149df9082b6deff491ba3c0130265b9c3f6f1 /cloudinit | |
parent | a7781de5e106fe6087a39afa20ff9f1fa0e37ff4 (diff) | |
download | vyos-cloud-init-5682ecb6649f65173a92d80e024e32e7d1cf7359.tar.gz vyos-cloud-init-5682ecb6649f65173a92d80e024e32e7d1cf7359.zip |
Seperated chef gems install to another function
Diffstat (limited to 'cloudinit')
-rw-r--r-- | cloudinit/CloudConfig/cc_chef.py | 40 |
1 files changed, 24 insertions, 16 deletions
diff --git a/cloudinit/CloudConfig/cc_chef.py b/cloudinit/CloudConfig/cc_chef.py index 335344d5..63e3808a 100644 --- a/cloudinit/CloudConfig/cc_chef.py +++ b/cloudinit/CloudConfig/cc_chef.py @@ -32,22 +32,17 @@ def handle(name,cfg,cloud,log,args): chef_cfg = cfg['chef'] # Install chef packages from selected source - if chef_cfg['install_type'] == "gems": - ruby_version = util.get_cfg_option_str(chef_cfg, 'ruby_version', '1.8') - cc.install_packages(ruby_packages['ruby_version']) - chef_version_arg = "" - if chef_cfg.has_key('version'): - chef_version_arg = '-v %s' % chef_cfg['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 - else: - cc.install_packages(('chef',)) + if not os.path.isfile('/usr/bin/chef-client'): + if chef_cfg['install_type'] == "gems": + if chef_cfg.has_key('version'): + chef_version = chef_cfg['version'] + else: + chef_version = None + install_chef_from_gems( + util.get_cfg_option_str(chef_cfg, 'ruby_version', '1.8'), + chef_version) + else: + cc.install_packages(('chef',)) # set the validation cert if chef_cfg.has_key('validation_cert'): @@ -70,3 +65,16 @@ def handle(name,cfg,cloud,log,args): # and finally, run chef 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 |