diff options
| author | Vlastimil Holer <vlastimil.holer@gmail.com> | 2012-12-19 18:03:03 +0100 | 
|---|---|---|
| committer | Vlastimil Holer <vlastimil.holer@gmail.com> | 2012-12-19 18:03:03 +0100 | 
| commit | 8dd9678d97a822e477915c150d528096a83c9777 (patch) | |
| tree | a9b5708edd9d448508abf00abdd9b7bdeba16541 /cloudinit/config/cc_chef.py | |
| parent | a9939fe768e04d52fe530c7467357d79b78a21f4 (diff) | |
| parent | 3569e71a1579b97f4e33fb46ab3fcef08a4ddad4 (diff) | |
| download | vyos-cloud-init-8dd9678d97a822e477915c150d528096a83c9777.tar.gz vyos-cloud-init-8dd9678d97a822e477915c150d528096a83c9777.zip | |
Merged trunk lp:cloud-init
Diffstat (limited to 'cloudinit/config/cc_chef.py')
| -rw-r--r-- | cloudinit/config/cc_chef.py | 45 | 
1 files changed, 28 insertions, 17 deletions
| diff --git a/cloudinit/config/cc_chef.py b/cloudinit/config/cc_chef.py index 6f568261..607f789e 100644 --- a/cloudinit/config/cc_chef.py +++ b/cloudinit/config/cc_chef.py @@ -22,10 +22,22 @@ import json  import os  from cloudinit import templater +from cloudinit import url_helper  from cloudinit import util  RUBY_VERSION_DEFAULT = "1.8" +CHEF_DIRS = [ +    '/etc/chef', +    '/var/log/chef', +    '/var/lib/chef', +    '/var/cache/chef', +    '/var/backups/chef', +    '/var/run/chef', +] + +OMNIBUS_URL = "https://www.opscode.com/chef/install.sh" +  def handle(name, cfg, cloud, log, _args): @@ -37,24 +49,15 @@ def handle(name, cfg, cloud, log, _args):      chef_cfg = cfg['chef']      # Ensure the chef directories we use exist -    c_dirs = [ -        '/etc/chef', -        '/var/log/chef', -        '/var/lib/chef', -        '/var/cache/chef', -        '/var/backups/chef', -        '/var/run/chef', -    ] -    for d in c_dirs: -        util.ensure_dir(cloud.paths.join(False, d)) +    for d in CHEF_DIRS: +        util.ensure_dir(d)      # Set the validation key based on the presence of either 'validation_key'      # or 'validation_cert'. In the case where both exist, 'validation_key'      # takes precedence      for key in ('validation_key', 'validation_cert'):          if key in chef_cfg and chef_cfg[key]: -            v_fn = cloud.paths.join(False, '/etc/chef/validation.pem') -            util.write_file(v_fn, chef_cfg[key]) +            util.write_file('/etc/chef/validation.pem', chef_cfg[key])              break      # Create the chef config from template @@ -68,8 +71,7 @@ def handle(name, cfg, cloud, log, _args):                                                     '_default'),              'validation_name': chef_cfg['validation_name']          } -        out_fn = cloud.paths.join(False, '/etc/chef/client.rb') -        templater.render_to_file(template_fn, out_fn, params) +        templater.render_to_file(template_fn, '/etc/chef/client.rb', params)      else:          log.warn("No template found, not rendering to /etc/chef/client.rb") @@ -81,11 +83,12 @@ def handle(name, cfg, cloud, log, _args):          initial_attributes = chef_cfg['initial_attributes']          for k in list(initial_attributes.keys()):              initial_json[k] = initial_attributes[k] -    firstboot_fn = cloud.paths.join(False, '/etc/chef/firstboot.json') -    util.write_file(firstboot_fn, json.dumps(initial_json)) +    util.write_file('/etc/chef/firstboot.json', json.dumps(initial_json))      # If chef is not installed, we install chef based on 'install_type' -    if not os.path.isfile('/usr/bin/chef-client'): +    if (not os.path.isfile('/usr/bin/chef-client') or +        util.get_cfg_option_bool(chef_cfg, 'force_install', default=False)): +          install_type = util.get_cfg_option_str(chef_cfg, 'install_type',                                                 'packages')          if install_type == "gems": @@ -101,6 +104,14 @@ def handle(name, cfg, cloud, log, _args):          elif install_type == 'packages':              # this will install and run the chef-client from packages              cloud.distro.install_packages(('chef',)) +        elif install_type == 'omnibus': +            url = util.get_cfg_option_str(chef_cfg, "omnibus_url", OMNIBUS_URL) +            content = url_helper.readurl(url=url, retries=5) +            with util.tempdir() as tmpd: +                # use tmpd over tmpfile to avoid 'Text file busy' on execute +                tmpf = "%s/chef-omnibus-install" % tmpd +                util.write_file(tmpf, content, mode=0700) +                util.subp([tmpf], capture=False)          else:              log.warn("Unknown chef install type %s", install_type) | 
