Permalink
Browse files

Merge branch 'develop'

  • Loading branch information...
2 parents d204ce8 + 3c34203 commit 115e3bb1c757626ba893e3e8539a826271eac312 @xdissent committed Apr 13, 2012
@@ -325,7 +325,7 @@ def run
def bootstrap_for_node(server, ssh_address)
bootstrap = Chef::Knife::Bootstrap.new
bootstrap.name_args = [ ssh_address ]
- bootstrap.config[:run_list] = config[:run_list]
+ bootstrap.config[:run_list] = config[:run_list] + ["recipe[hatch]"]
bootstrap.config[:ssh_user] = config[:ssh_user]
bootstrap.config[:identity_file] = config[:identity_file]
bootstrap.config[:chef_node_name] = config[:chef_node_name] || server.id
@@ -425,7 +425,7 @@ def bootstrap_for_node(server, ssh_address)
puts "#{ui.color("Finishing hatching and restarting chef-client", :cyan)}"
Net::SSH.start(ssh_address, config[:ssh_user], :keys => [config[:identity_file]]) do |ssh|
- ssh.exec! "cd /tmp/chef-hatch && sudo rake hatch:finish['#{bootstrap.config[:chef_node_name]}','#{config[:run_list].join(' ')}','#{config[:environment]}']"
+ ssh.exec! "cd /tmp/chef-hatch && sudo rake hatch:finish"
ssh.exec! "sudo /etc/init.d/chef-client restart"
end
View
@@ -5,4 +5,3 @@
.vagrant
tmp/
cookbooks/
-Cheffile.lock
View
@@ -1,3 +1,9 @@
+## 0.2.1 (April 13, 2012)
+
+ - Commit Cheffile.lock
+ - Move everything into hatch folder (that doesn't use knife).
+ - Save node data after solo run and restore attributes on server
+
## 0.2.0 (April 12, 2012)
- Librarian support (https://github.com/xdissent/chef-hatch-repo/pull/5)
View
@@ -3,6 +3,9 @@
site 'http://community.opscode.com/api/v1'
+cookbook "hatch",
+ :path => "hatch/cookbook"
+
cookbook 'apache2'
cookbook 'apt'
cookbook 'bluepill'
View
@@ -0,0 +1,77 @@
+SITE
+ remote: http://community.opscode.com/api/v1
+ specs:
+ apache2 (1.1.6)
+ apt (1.4.0)
+ bluepill (1.0.4)
+ build-essential (1.0.0)
+ chef-client (1.1.2)
+ chef-server (0.99.12)
+ apache2 (>= 0.0.0)
+ bluepill (>= 0.0.0)
+ couchdb (>= 0.0.0)
+ daemontools (>= 0.0.0)
+ gecode (>= 0.0.0)
+ java (>= 0.0.0)
+ nginx (>= 0.0.0)
+ openssl (>= 0.0.0)
+ runit (>= 0.0.0)
+ xml (>= 0.0.0)
+ zlib (>= 0.0.0)
+ couchdb (1.0.0)
+ erlang (>= 0.0.0)
+ daemontools (0.9.0)
+ build-essential (>= 0)
+ ucspi-tcp (>= 0)
+ erlang (1.0.0)
+ yum (>= 0.5.0)
+ gecode (1.2.0)
+ apt (>= 0.0.0)
+ build-essential (>= 0.0.0)
+ nginx (0.101.0)
+ bluepill (>= 0.0.0)
+ build-essential (>= 0.0.0)
+ ohai (~> 1.0.2)
+ runit (>= 0.0.0)
+ ohai (1.0.2)
+ openssl (1.0.0)
+ runit (0.15.0)
+ ucspi-tcp (1.0.0)
+ build-essential (>= 0)
+ xml (1.0.2)
+ yum (0.5.2)
+ zlib (1.0.0)
+
+GIT
+ remote: https://github.com/cjAdvertising/chef-java.git
+ ref: master
+ sha: 957356a6f38fdf9b3a2a23b031a81930fc60bbeb
+ specs:
+ java (1.5.1)
+
+PATH
+ remote: hatch/cookbook
+ specs:
+ hatch (0.0.1)
+
+DEPENDENCIES
+ apache2 (>= 0)
+ apt (>= 0)
+ bluepill (>= 0)
+ build-essential (>= 0)
+ chef-client (>= 0)
+ chef-server (>= 0)
+ couchdb (>= 0)
+ daemontools (>= 0)
+ erlang (>= 0)
+ gecode (>= 0)
+ hatch (>= 0)
+ java (>= 0)
+ nginx (>= 0)
+ openssl (>= 0)
+ runit (>= 0)
+ ucspi-tcp (>= 0)
+ xml (>= 0)
+ yum (>= 0)
+ zlib (>= 0)
+
View
@@ -52,7 +52,7 @@ Getting Started
The Hatch repository has been forked from the official Opscode chef-repo
repository. That means it's a convenient starting point for your own Chef
-repository. To begin, clone the Hatch repository::
+repository. To begin, clone the Hatch repository:
Stewart:Code xdissent$ git clone https://github.com/xdissent/chef-hatch-repo.git
Cloning into chef-hatch-repo...
@@ -64,12 +64,17 @@ repository. To begin, clone the Hatch repository::
Stewart:Code xdissent$ cd chef-hatch-repo/
-Cookbooks are managed by `Librarian`_ and must be installed before use::
+Cookbooks are managed by [Librarian](https://github.com/applicationsonline/librarian)
+and must be installed before use:
Stewart:chef-hatch-repo(master) xdissent$ librarian-chef install
+
+To update the cookbooks to the latest available versions, run
+`librarian-chef update`. See the [Librarian](https://github.com/applicationsonline/librarian)
+documentation for more info.
-Then hatch a Chef server in a virtual machine::
+Then hatch a Chef server in a virtual machine:
Stewart:chef-hatch-repo(master) xdissent$ vagrant up chef
[chef] Provisioning enabled with HatchProvisioner...
@@ -111,7 +116,7 @@ Then hatch a Chef server in a virtual machine::
[chef] Grabbing validation key
-The Chef server can be managed using the `knife` command::
+The Chef server can be managed using the `knife` command:
Stewart:chef-hatch-repo(master) xdissent$ knife status
5 minutes ago, chef.local, chef.local, 10.0.2.15, ubuntu 10.04.
View
@@ -75,10 +75,15 @@ namespace :hatch do
c.cdb_save
puts "Created #{args.client_name} admin client."
end
- task :finish, :node_name, :run_list, :environ do |t, args|
- n = Chef::Node.cdb_load(args.node_name)
- n.chef_environment(args.environ)
- n.run_list.reset!(args.run_list.split)
+ task :finish do |t, args|
+ genes = JSON.parse(File.open("/tmp/chef-hatch-genes.json", 'r') { |f| f.read })
+ run_list = genes.run_list.dup
+ run_list.delete "recipe[hatch]"
+ n = Chef::Node.cdb_load(genes.name)
+ n.chef_environment(genes.chef_environment)
+ n.run_list.reset!(run_list)
+ n.normal_attrs = genes.normal_attrs
n.cdb_save
+ File.delete("/tmp/chef-hatch-genes.json")
end
end
View
@@ -1,4 +1,4 @@
-require './hatch_provisioner'
+require './hatch/provisioner'
Vagrant::Config.run do |config|
View
@@ -0,0 +1,9 @@
+Description
+===========
+
+This cookbook contains a single recipe, which dumps a JSON representation
+of the node to a tmp file. The hatch:finish rake task will then save this
+node data on the (now running) Chef server.
+
+Do not use this cookbook directly. The appropriate run_list entries will
+be created automatically when hatching as server.
@@ -0,0 +1,6 @@
+maintainer "Greg Thornton"
+maintainer_email "xdissent@me.com"
+license "MIT"
+description "Installs/Configures hatch"
+long_description IO.read(File.join(File.dirname(__FILE__), 'README.md'))
+version "0.0.1"
@@ -0,0 +1,31 @@
+#
+# Cookbook Name:: hatch
+# Recipe:: default
+#
+# Copyright 2012, Greg Thornton
+#
+# Permission is hereby granted, free of charge, to any person obtaining
+# a copy of this software and associated documentation files (the
+# "Software"), to deal in the Software without restriction, including
+# without limitation the rights to use, copy, modify, merge, publish,
+# distribute, sublicense, and/or sell copies of the Software, and to
+# permit persons to whom the Software is furnished to do so, subject to
+# the following conditions:
+#
+# The above copyright notice and this permission notice shall be
+# included in all copies or substantial portions of the Software.
+#
+# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+# EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+# MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+# NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
+# LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
+# OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
+# WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+#
+
+# Dump the node as JSON so the hatch:finish rake task can
+# save our attributes to the server
+file "/tmp/chef-hatch-genes.json" do
+ content node.to_json
+end
File renamed without changes.
@@ -1,5 +1,7 @@
I18n.load_path << File.expand_path("../locales/en.yml", __FILE__)
+HATCH_ROOT = File.expand_path("..", File.dirname(__FILE__))
+
class HatchProvisioner < Vagrant::Provisioners::ChefSolo
I18N_NAMESPACE = "vagrant.provisioners.hatch"
@@ -44,12 +46,13 @@ def prepare
if ((env[:vm].config.vm.networks[0] || [])[1] || [])[0].nil?
raise HatchError, :require_chef_ip if config.chef_ip.nil?
end
+ config.add_recipe("hatch")
super
end
def provision!
env[:ui].info I18n.t("#{I18N_NAMESPACE}.running_bootstrap")
- env[:vm].channel.sudo("sh /vagrant/.chef/bootstrap/vagrant-hatch.sh")
+ env[:vm].channel.sudo("sh /vagrant/hatch/vagrant.sh")
super
@@ -71,7 +74,7 @@ def provision!
`for role in roles/*.rb ; do knife role from file $role ; done`
# Find and upload all data bags
- dbag_glob = File.expand_path(File.join(File.dirname(__FILE__), config.data_bags_path)) + "/*/*.json"
+ dbag_glob = File.join(HATCH_ROOT, config.data_bags_path) + "/*/*.json"
dbags = []
Dir.glob(dbag_glob) do |f|
bag = File.basename(File.dirname(f))
@@ -86,7 +89,7 @@ def provision!
end
# Create environments
- env_glob = File.expand_path(File.join(File.dirname(__FILE__), "/environments")) + "/*.rb"
+ env_glob = File.join(HATCH_ROOT, "/environments") + "/*.rb"
Dir.glob(env_glob) do |f|
env[:ui].info I18n.t("#{I18N_NAMESPACE}.uploading_environment", :name => f)
`knife environment from file #{File.basename(f)}`
@@ -95,27 +98,26 @@ def provision!
n = config.node_name || env.config.vm.host_name
env[:ui].info I18n.t("#{I18N_NAMESPACE}.running_hatch_finish")
- env[:vm].channel.sudo("cd /vagrant && rake hatch:finish['#{n}','#{config.run_list.join(' ')}','#{config.environment}']")
+ env[:vm].channel.sudo("cd /vagrant && rake hatch:finish")
env[:ui].info I18n.t("#{I18N_NAMESPACE}.restarting_chef_client")
env[:vm].channel.sudo("/etc/init.d/chef-client restart")
end
def setup_knife_config
- cwd = File.expand_path(File.dirname(__FILE__))
conf = <<-END_CONF
log_level #{config.log_level}
log_location STDOUT
node_name '#{config.client_name}'
- client_key '#{cwd}/#{config.client_key_path}'
+ client_key '#{HATCH_ROOT}/#{config.client_key_path}'
validation_client_name '#{config.validation_client_name}'
- validation_key '#{cwd}/#{config.validation_key_path}'
+ validation_key '#{HATCH_ROOT}/#{config.validation_key_path}'
chef_server_url 'http://#{config.chef_ip || env[:vm].config.vm.networks[0][1][0]}:4000'
cache_type 'BasicFile'
- cache_options( :path => '#{cwd}/.chef/checksums' )
- cookbook_path [ '#{cwd}/cookbooks' ]
+ cache_options( :path => '#{HATCH_ROOT}/.chef/checksums' )
+ cookbook_path [ '#{HATCH_ROOT}/cookbooks' ]
END_CONF
- config_file = File.new("#{cwd}/.chef/knife.rb", "w")
+ config_file = File.new("#{HATCH_ROOT}/.chef/knife.rb", "w")
config_file.write(conf)
config_file.close
env[:ui].info I18n.t("#{I18N_NAMESPACE}.wrote_configuration", :conf => conf)
File renamed without changes.

0 comments on commit 115e3bb

Please sign in to comment.