lib/capistrano-chef-solo.rb in yyuu-capistrano-chef-solo-0.0.4 vs lib/capistrano-chef-solo.rb in yyuu-capistrano-chef-solo-0.0.5

- old
+ new

@@ -65,51 +65,51 @@ invoke } task(:update_cookbooks) { tmpdir = Dir.mktmpdir() - remote_tmpdir = Dir.mktmpdir() + remote_tmpdir = capture("mktemp -d").chomp destination = File.join(tmpdir, 'cookbooks') remote_destination = File.join(chef_solo_path, 'cookbooks') filename = File.join(tmpdir, 'cookbooks.tar.gz') remote_filename = File.join(remote_tmpdir, 'cookbooks.tar.gz') begin bundle_cookbooks(filename, destination) run("mkdir -p #{remote_tmpdir}") distribute_cookbooks(filename, remote_filename, remote_destination) ensure - run("rm -rf #{remote_tmpdir}") - run_locally("rm -rf #{tmpdir}") + run("rm -rf #{remote_tmpdir}") rescue nil + run_locally("rm -rf #{tmpdir}") rescue nil end } - _cset(:chef_solo_cookbook_repository) { abort("chef_solo_cookbook_repository not set") } - _cset(:chef_solo_cookbooks_repository) { + # s/cookbook/&s/g for backward compatibility with releases older than 0.0.2. + # they will be removed in future releases. + _cset(:chef_solo_cookbook_repository) { logger.info("WARNING: `chef_solo_cookbook_repository' has been deprecated. use `chef_solo_cookbooks_repository' instead.") - chef_solo_cookbook_repository + abort("chef_solo_cookbook_repository not set") } - _cset(:chef_solo_cookbook_revision, 'HEAD') - _cset(:chef_solo_cookbooks_revision) { + _cset(:chef_solo_cookbook_revision) { logger.info("WARNING: `chef_solo_cookbook_revision' has been deprecated. use `chef_solo_cookbooks_revision' instead.") - chef_solo_cookbook_revision + "HEAD" } - _cset(:chef_solo_cookbook_subdir, '/') - _cset(:chef_solo_cookbooks_subdir) { + _cset(:chef_solo_cookbook_subdir) { logger.info("WARNING: `chef_solo_cookbook_subdir' has been deprecated. use `chef_solo_cookbooks_subdir' instead.") - chef_solo_cookbook_subdir + "/" } _cset(:chef_solo_cookbooks_exclude, %w(.hg .git .svn)) # special variable to set multiple cookbooks repositories. # by default, it will build from :chef_solo_cookbooks_* variables. _cset(:chef_solo_cookbooks) { - name = File.basename(chef_solo_cookbooks_repository, File.extname(chef_solo_cookbooks_repository)) + repository = fetch(:chef_solo_cookbooks_repository, fetch(:chef_solo_cookbook_repository, nil)) + name = File.basename(repository, File.extname(repository)) { name => { - :repository => chef_solo_cookbooks_repository, - :revision => chef_solo_cookbooks_revision, - :cookbooks => chef_solo_cookbooks_subdir, + :repository => repository, + :revision => fetch(:chef_solo_cookbooks_revision, fetch(:chef_solo_cookbook_revision, nil)), + :cookbooks => fetch(:chef_solo_cookbooks_subdir, fetch(:chef_solo_cookbook_subdir, nil)), :cookbooks_exclude => chef_solo_cookbooks_exclude, } } } @@ -169,21 +169,29 @@ def _deep_merge(a, b) f = lambda { |key, val1, val2| Hash === val1 && Hash === val2 ? val1.merge(val2, &f) : val2 } a.merge(b, &f) end + def _json(x) + if fetch(:chef_solo_pretty_json, true) + JSON.pretty_generate(x) + else + JSON.generate(x) + end + end + _cset(:chef_solo_attributes, {}) _cset(:chef_solo_host_attributes, {}) task(:update_attributes) { attributes = _deep_merge(chef_solo_attributes, {'run_list' => fetch(:chef_solo_run_list, [])}) to = File.join(chef_solo_path, 'config', 'solo.json') if chef_solo_host_attributes.empty? - put(attributes.to_json, to) + put(_json(attributes), to) else execute_on_servers { |servers| servers.each { |server| host_attributes = _deep_merge(attributes, chef_solo_host_attributes.fetch(server.host, {})) - Capistrano::Transfer.process(:up, StringIO.new(host_attributes.to_json), to, [sessions[server]], :logger => logger) + Capistrano::Transfer.process(:up, StringIO.new(_json(host_attributes)), to, [sessions[server]], :logger => logger) } } end }