From 085cced7723215b739395b6af54b5dba419e80bf Mon Sep 17 00:00:00 2001 From: John Bellone Date: Thu, 13 Nov 2014 15:03:54 -0800 Subject: [PATCH] Add chef-provisioning recipe for easy bootstrapping. --- README.md | 44 ++++++++++++++++++++++++++++++++------------ cluster.rb | 37 +++++++++++++++++++++++++++++++++++++ metadata.rb | 3 ++- 3 files changed, 71 insertions(+), 13 deletions(-) create mode 100644 cluster.rb diff --git a/README.md b/README.md index 8873dc5f..443eebfe 100644 --- a/README.md +++ b/README.md @@ -4,13 +4,13 @@ consul-cookbook [![Build Status](http://img.shields.io/travis/johnbellone/consul-cookbook.svg)][5] [![Code Coverage](http://img.shields.io/coveralls/johnbellone/consul-cookbook.svg)][6] -Installs and configures [Consul][1]. +Installs and configures [Consul][1] client, server and UI. ## Supported Platforms - CentOS 5.10, 6.5, 7.0 - RHEL 5.10, 6.5, 7.0 -- Ubuntu 12.04, 14.04 +- Ubuntu 10.04, 12.04, 14.04 ## Attributes @@ -212,14 +212,31 @@ Installs and configures [Consul][1]. ## Usage +The easiest way to bootstrap a cluster is to use the cluster recipe +and use [Chef provisioning][7] which is a relatively new +extension. This extension allows you to use any driver and easily +stand up a cluster. Once the [Chef Development Kit][8] has been +installed you can run the following command to provision a cluster. + +```ruby +gem install chef-provisioning chef-provisioning-fog +export CHEF_DRIVER=fog:AWS +chef-client -z cluster.rb +``` -### consul::default +Please follow the [Chef provisioning README][9] which provides more +detailed information about provisioning. You'll need to configure +your credentials prior to provisioning. -This uses the binary installation recipe by default. It also starts consul at boot time. +### consul::default +The default recipe will install the Consul agent using the +`consul::install_binary` recipe. It will also configure and +start consul at the machine boot. ### consul::install_binary - -Include `consul::install_binary` in your node's `run_list`: +If you only wish to simply install the binary from the official +mirror you simply include `consul::install_binary` in your node's +`run_list`: ```json { @@ -230,8 +247,10 @@ Include `consul::install_binary` in your node's `run_list`: ``` ### consul::install_source - -Include `consul::install_source` in your node's `run_list`: +Instead if you wish to install Consul from source you simply need +to include `consul::install_source` in your node's `run_list`. This +will also configure the Go language framework on the node to build +the application. ```json { @@ -242,10 +261,8 @@ Include `consul::install_source` in your node's `run_list`: ``` ### consul::ui - -This installs the UI into a specified directory. - -Include `consul::ui` in your node's `run_list`: +Installing the separate Consul UI simply requires you to include +the `consul::ui` recipe in your node's `run_list`. ```json { @@ -320,3 +337,6 @@ Created and maintained by [John Bellone][3] [@johnbellone][2] ( +# Copyright 2014 Bloomberg Finance L.P. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# +num_quorum = ENV.fetch('CONSUL_QUORUM', 3) + +batch = machine_batch do + 1.upto(num_quorum).each do |index| + machine "consul-#{index}" do + recipe 'consul::default' + attributes(consul: { service_mode: 'cluster' }) + end + end +end + +include_recipe 'chef-sugar::default' +node.default['consul']['servers'] = batch.machines.each { |m| best_ip_for(m.node) } + +machine 'consul-ui' do + recipe 'consul::ui' + attributes(consul: { + service_mode: 'client', + servers: node['consul']['servers'] + }) +end diff --git a/metadata.rb b/metadata.rb index 36bca347..0b10edc9 100644 --- a/metadata.rb +++ b/metadata.rb @@ -22,6 +22,7 @@ supports 'ubuntu', '= 14.04' depends 'ark' -depends 'golang', '~> 1.5.0' +depends 'chef-provisioning' +depends 'golang', '~> 1.3.0' depends 'runit' depends 'yum-repoforge'