From 2e6b44be4a2c352a49910c437a830c27b0ad131c Mon Sep 17 00:00:00 2001 From: Mike Moulton Date: Tue, 13 Sep 2011 00:38:37 +0000 Subject: Bringing in proper json support for firstboot.json from lp:~avishai-ish-shalom/cloud-init/chef Bringing in 'initial_properties' support from lp:~avishai-ish-shalom/cloud-init/chef --- cloudinit/CloudConfig/cc_chef.py | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) (limited to 'cloudinit') diff --git a/cloudinit/CloudConfig/cc_chef.py b/cloudinit/CloudConfig/cc_chef.py index 1effba53..807c3717 100644 --- a/cloudinit/CloudConfig/cc_chef.py +++ b/cloudinit/CloudConfig/cc_chef.py @@ -18,6 +18,7 @@ import os import pwd import socket import subprocess +import json import StringIO import ConfigParser import cloudinit.CloudConfig as cc @@ -57,13 +58,13 @@ def handle(name,cfg,cloud,log,args): # set the firstboot json with open('/etc/chef/firstboot.json', 'w') as firstboot_json_fh: - firstboot_json_fh.write("{\n") + initial_json = {} if chef_cfg.has_key('run_list'): - firstboot_json_fh.write(" \"run_list\": [\n") - firstboot_json_fh.write(",\n".join([" \"%s\"" % runlist_item - for runlist_item in chef_cfg['run_list']])) - firstboot_json_fh.write("\n ]\n") - firstboot_json_fh.write("}\n") + initial_json['run_list'] = chef_cfg['run_list'] + if chef_cfg.has_key('initial_attributes'): + initial_attributes = chef_cfg['initial_attributes'] + for k in initial_attributes.keys(): initial_json[k] = initial_attributes[k] + firstboot_json_fh.write(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'): -- cgit v1.2.3