Skip to content
This repository has been archived by the owner on Nov 17, 2023. It is now read-only.

Commit

Permalink
Switch to commander, add default node name support
Browse files Browse the repository at this point in the history
  • Loading branch information
Vasily Mikhaylichenko committed Feb 27, 2013
1 parent d7bcf23 commit 11179c8
Show file tree
Hide file tree
Showing 7 changed files with 74 additions and 38 deletions.
15 changes: 11 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,14 @@ Provisioning a server
The following command will run all roles and recipes from node's YAML file.

```
gusteau node-name provision
gusteau -n node-name provision
```

You can avoid typing `-n node-name` each time by exporting a `GUSTEAU_NODE` environment variable:

```
export GUSTEAU_NODE="production-server"
gusteau provision
```

Use the `--bootstrap` or `-b` flag to bootstrap chef-solo (for the first time run).
Expand All @@ -78,15 +85,15 @@ Running recipes
You may choose to run a few recipes instead of full provisioning.

```
gusteau node-name run redis::server ntp unicorn
gusteau -n node-name run redis::server ntp unicorn
```

SSH
---
Gusteau provides a useful shortcut that you may use to ssh into a node. If you haven't got passwordless authentication set up, Gusteau will use `user` and `password` values from the node configuration.

```
gusteau ssh node-name
gusteau -n node-name ssh
```

Using with Vagrant
Expand All @@ -95,7 +102,7 @@ At the moment Gusteau doesn't come with Vagrant integration. However, using it w

```
vagrant up
gusteau node-name provision
gusteau provision
```

Notes
Expand Down
83 changes: 55 additions & 28 deletions bin/gusteau
Original file line number Diff line number Diff line change
@@ -1,51 +1,78 @@
#!/usr/bin/env ruby

require 'rubygems'
require 'optitron'
require 'gli'

$LOAD_PATH << File.expand_path("../..", __FILE__)
require 'lib/gusteau'

class Gusteau::CLI < Optitron::CLI
include GLI::App

class_opt 'bootstrap', 'Install chef-solo'
class_opt 'format', 'Output format to use', :short_name => 'F', :type => :string
class_opt 'log_level', 'Set the log level', :in => %w{debug info warn error fatal}
class_opt 'why-run', 'Enable whyrun mode', :short_name => 'W'
program_desc Gusteau::DESCRIPTION
version Gusteau::VERSION
sort_help :manually

desc 'Fully provision a node'
def provision(node_name)
node(node_name).provision(params)
end
default_node = ENV['GUSTEAU_NODE'] || 'vagrant'

desc 'Run recipe(s)'
def run(node_name, *recipe)
node(node_name).run(params, recipe)
end
desc 'Node to use'
flag [:n, :node], :arg_name => 'node', :default_value => default_node

desc 'Install chef-solo'
switch [:b, :bootstrap], :negatable => false

desc 'Output format to use'
flag ['F', 'format'], :arg_name => 'format'

desc 'SSH into a node'
def ssh(node_name)
node(node_name).ssh
desc 'Set the log level'
flag ['l', 'log_level'], :arg_name => 'log_level'

desc 'Enable whyrun node'
switch ['W', 'why-run'], :negatable => false

on_error {}

desc 'Fully provision a node'
command 'provision' do |c|
c.action do |global, options, args|
node(global[:node]).provision(options.merge global)
end
end

desc 'Generate an example project (a bureau)'
def generate(bureau_name)
Gusteau::Bureau.new(bureau_name)
desc 'Run recipe(s)'
command 'run' do |c|
c.arg_name 'recipe', :multiple

c.action do |global, options, args|
node(global[:node]).run(options.merge global, args)
end
end

private
desc 'SSH into a node'
command 'ssh' do |c|
c.action do |global, options, args|
node(global[:node]).ssh
end
end

def node(node_name)
unless node_path = Dir.glob("./nodes/**/#{node_name}.yml")[0]
abort "Node '#{node_name}' is unknown. Known nodes are #{nodes_list.join(', ')}."
end
Gusteau::Node.new(node_path)
end

def nodes_list
Dir.glob("./nodes/**/*.yml").map { |f| File.basename(f, '.*') }
desc 'Generate an example project (a bureau)'
command 'generate' do |c|
c.action do |global, options, args|
Gusteau::Bureau.new(args[0])
end
end

def node(node_name)
unless node_path = Dir.glob("./nodes/**/#{node_name}.yml")[0]
abort "Node '#{node_name}' is unknown. Known nodes are #{nodes_list.join(', ')}."
end
Gusteau::Node.new(node_path)
end

def nodes_list
Dir.glob("./nodes/**/*.yml").map { |f| File.basename(f, '.*') }
end

Gusteau::CLI.dispatch
exit run(ARGV)
4 changes: 2 additions & 2 deletions gusteau.gemspec
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
# -*- encoding: utf-8 -*-
lib = File.expand_path('../lib', __FILE__)
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
require 'gusteau/version'
require 'gusteau/metadata'

Gem::Specification.new do |gem|
gem.name = "gusteau"
gem.version = Gusteau::VERSION
gem.authors = ["Vasily Mikhaylichenko", "Chris"]
gem.email = ["vasily@locomote.com", "chris@locomote.com"]
gem.description = %q{A fine Chef Solo wrapper}
gem.description = Gusteau::DESCRIPTION
gem.summary = %q{Making servers provisioning enjoyable since 2013.}
gem.homepage = "http://gusteau.gs"

Expand Down
1 change: 1 addition & 0 deletions lib/gusteau.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,5 @@
module Gusteau
require 'gusteau/node'
require 'gusteau/bureau'
require 'gusteau/metadata'
end
4 changes: 4 additions & 0 deletions lib/gusteau/metadata.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
module Gusteau
VERSION = "0.4.2"
DESCRIPTION = %q{A fine Chef Solo wrapper}
end
2 changes: 1 addition & 1 deletion lib/gusteau/node.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

module Gusteau
class Node
attr_reader :server
attr_reader :name, :server

def initialize(path)
raise "Node YAML file #{path} not found" unless path && File.exists?(path)
Expand Down
3 changes: 0 additions & 3 deletions lib/gusteau/version.rb

This file was deleted.

0 comments on commit 11179c8

Please sign in to comment.