knife-solo 0.0.12 → 0.0.13

Sign up to get free protection for your applications and to get access to all the features.
@@ -20,6 +20,8 @@ class Chef
20
20
  include KnifeSolo::KitchenCommand
21
21
  include KnifeSolo::Tools
22
22
 
23
+ class WrongCookError < KnifeSolo::KnifeSoloError; end
24
+
23
25
  banner "knife cook [user@]hostname [json] (options)"
24
26
 
25
27
  option :skip_chef_check,
@@ -37,9 +39,16 @@ class Chef
37
39
  :boolean => true,
38
40
  :description => "Skip Ruby syntax checks"
39
41
 
42
+ option :syntax_check_only,
43
+ :long => '--syntax-check-only',
44
+ :boolean => true,
45
+ :description => "Only run syntax checks - do not run Chef"
46
+
40
47
  def run
48
+ validate_params!
41
49
  super
42
50
  check_syntax unless config[:skip_syntax_check]
51
+ return if config[:syntax_check_only]
43
52
  Chef::Config.from_file('solo.rb')
44
53
  check_chef_version unless config[:skip_chef_check]
45
54
  rsync_kitchen
@@ -63,6 +72,7 @@ class Chef
63
72
  raise "Syntax error in #{json}: #{error.message}"
64
73
  end
65
74
  end
75
+ Chef::Log.info "cookbook and json syntax is ok"
66
76
  end
67
77
 
68
78
  def node_config
@@ -109,7 +119,7 @@ class Chef
109
119
  BASH
110
120
  raise "Couldn't find Chef #{CHEF_VERSION_CONSTRAINT} on #{host}. Please run `#{$0} prepare #{ssh_args}` to ensure Chef is installed and up to date." unless result.success?
111
121
  end
112
-
122
+
113
123
  def cook
114
124
  logging_arg = "-l debug" if config[:verbosity] > 0
115
125
 
@@ -119,6 +129,11 @@ class Chef
119
129
  #{logging_arg}
120
130
  BASH
121
131
  end
132
+
133
+ def validate_params!
134
+ validate_first_cli_arg_is_a_hostname!(WrongCookError)
135
+ end
136
+
122
137
  end
123
138
  end
124
139
  end
@@ -15,7 +15,7 @@ class Chef
15
15
  class WrongPrepareError < KnifeSolo::KnifeSoloError
16
16
  alias :message :to_s
17
17
  end
18
-
18
+
19
19
  banner "knife prepare [user@]hostname (options)"
20
20
 
21
21
  option :omnibus_version,
@@ -46,9 +46,7 @@ class Chef
46
46
  end
47
47
 
48
48
  def validate_params!
49
- unless @name_args.first =~ /\A.+\@.+\z/
50
- raise WrongPrepareError.new "need to pass a [user@]hostname as the first argument"
51
- end
49
+ validate_first_cli_arg_is_a_hostname!(WrongPrepareError)
52
50
  end
53
51
  end
54
52
  end
@@ -23,6 +23,10 @@ module KnifeSolo
23
23
  end
24
24
 
25
25
  module Delegates
26
+ def stream_command(cmd)
27
+ prepare.stream_command(cmd)
28
+ end
29
+
26
30
  def run_command(cmd)
27
31
  prepare.run_command(cmd)
28
32
  end
@@ -52,18 +56,25 @@ module KnifeSolo
52
56
  end
53
57
 
54
58
  def http_client_get_url(url)
55
- "wget #{url}"
59
+ file = File.basename(url)
60
+ stream_command <<-BASH
61
+ if which curl 2>/dev/null; then
62
+ curl -L -o #{file} #{url}
63
+ else
64
+ wget -O #{file} #{url}
65
+ fi
66
+ BASH
56
67
  end
57
68
 
58
69
  def omnibus_install
59
- run_command(http_client_get_url("http://opscode.com/chef/install.sh"))
70
+ http_client_get_url("http://opscode.com/chef/install.sh")
60
71
 
61
72
  # `release_version` within install.sh will be installed if
62
73
  # `omnibus_version` is not provided.
63
74
  install_command = "sudo bash install.sh"
64
75
  install_command << " -v #{prepare.config[:omnibus_version]}" if prepare.config[:omnibus_version]
65
76
 
66
- run_command(install_command)
77
+ stream_command(install_command)
67
78
  end
68
79
 
69
80
  def ubuntu_omnibus_install
@@ -80,7 +91,7 @@ module KnifeSolo
80
91
  release = "rubygems-1.8.10"
81
92
  file = "#{release}.tgz"
82
93
  url = "http://production.cf.rubygems.org/rubygems/#{file}"
83
- run_command(http_client_get_url(url))
94
+ http_client_get_url(url)
84
95
  run_command("tar zxf #{file}")
85
96
  run_command("cd #{release} && sudo ruby setup.rb --no-format-executable")
86
97
  run_command("sudo rm -rf #{release} #{file}")
@@ -8,7 +8,7 @@ module KnifeSolo::Bootstraps
8
8
  def gem_packages
9
9
  ['chef']
10
10
  end
11
-
11
+
12
12
  def distro
13
13
  case issue
14
14
  when %r{10.5}
@@ -25,11 +25,6 @@ module KnifeSolo::Bootstraps
25
25
  result.success?
26
26
  end
27
27
 
28
- def http_client_get_url(url)
29
- filename = url.split("/").last
30
- "curl '#{url}' >> #{filename}"
31
- end
32
-
33
28
  def run_pre_bootstrap_checks
34
29
  raise 'xcode not installed, which is required to do anything. please install and run again.' unless has_xcode_installed?
35
30
  end
@@ -0,0 +1,57 @@
1
+ module KnifeSolo::Bootstraps
2
+ class FreeBSD < Base
3
+ def issue
4
+ run_command("uname -sr").stdout.strip
5
+ end
6
+
7
+ def gem_packages
8
+ ['chef']
9
+ end
10
+
11
+ def prepare_make_conf
12
+ ui.msg "Preparing make.conf"
13
+ run_command <<-EOF
14
+ echo 'RUBY_DEFAULT_VER=1.9' >> /etc/make.conf
15
+ EOF
16
+ end
17
+
18
+ def freebsd_port_install
19
+ ui.msg "Updating ports tree..."
20
+
21
+ if Dir["/usr/ports/*"].empty?
22
+ run_command("portsnap fetch extract")
23
+ else
24
+ run_command("portsnap update")
25
+ end
26
+
27
+ prepare_make_conf
28
+
29
+ ui.msg "Installing required ports..."
30
+ packages = %w(net/rsync ftp/curl lang/ruby19 devel/ruby-gems
31
+ converters/ruby-iconv devel/rubygem-rake
32
+ shells/bash)
33
+
34
+ packages.each do |p|
35
+ ui.msg "Installing #{p}..."
36
+ result = run_command <<-SH
37
+ cd /usr/ports/#{p} && make -DBATCH -DFORCE_PKG_REGISTER install clean
38
+ SH
39
+ raise "Couldn't install #{p} from ports." unless result.success?
40
+ end
41
+
42
+ ui.msg "...done installing ports."
43
+
44
+ gem_install # chef
45
+ end
46
+
47
+ def distro
48
+ return @distro if @distro
49
+ case issue
50
+ when %r{FreeBSD 9.0-RELEASE}
51
+ {:type => 'freebsd_port'}
52
+ else
53
+ raise "#{issue} not supported"
54
+ end
55
+ end
56
+ end
57
+ end
@@ -13,10 +13,6 @@ module KnifeSolo::Bootstraps
13
13
  ['ruby-shadow','chef']
14
14
  end
15
15
 
16
- def http_client_get_url(url)
17
- "curl -LO #{url}"
18
- end
19
-
20
16
  def zypper_gem_install
21
17
  ui.msg("Installing required packages...")
22
18
  run_command("sudo zypper --non-interactive install ruby-devel make gcc rsync")
@@ -1,5 +1,5 @@
1
1
  module KnifeSolo
2
2
  def self.version
3
- '0.0.12'
3
+ '0.0.13'
4
4
  end
5
5
  end
@@ -8,28 +8,36 @@ module KnifeSolo
8
8
  end
9
9
  end
10
10
 
11
- def self.required_directories
12
- %w(nodes roles cookbooks data_bags site-cookbooks)
13
- end
14
-
15
11
  def self.required_files
16
12
  %w(solo.rb)
17
13
  end
18
14
 
19
- def self.all_requirements
20
- required_files + required_directories
21
- end
22
-
23
15
  def run
24
16
  raise OutOfKitchenError.new unless required_files_present?
25
17
  end
26
18
 
27
19
  def required_files_present?
28
- KitchenCommand.all_requirements.inject(true) do |m, f|
20
+ KitchenCommand.required_files.inject(true) do |m, f|
29
21
  check = File.exists?(f)
30
- Chef::Log.warn "#{f} is a required file/directory" unless check
22
+ warn_for_required_file(f) unless check
31
23
  m && check
32
24
  end
33
25
  end
26
+
27
+ def warn_for_required_file(file)
28
+ Chef::Log.warn "#{file} is a required file/directory"
29
+ end
30
+
31
+ def first_cli_arg_is_a_hostname?
32
+ @name_args.first =~ /\A.+\@.+\z/
33
+ end
34
+
35
+ def validate_first_cli_arg_is_a_hostname!(error_class)
36
+ unless first_cli_arg_is_a_hostname?
37
+ ui.msg opt_parser.help
38
+ raise error_class.new "need to pass atleast a [user@]hostname as the first argument"
39
+ end
40
+ end
41
+
34
42
  end
35
43
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: knife-solo
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.12
4
+ version: 0.0.13
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2012-06-26 00:00:00.000000000 Z
12
+ date: 2012-08-16 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: rake
@@ -110,6 +110,7 @@ files:
110
110
  - lib/chef/knife/prepare.rb
111
111
  - lib/chef/knife/wash_up.rb
112
112
  - lib/knife-solo/bootstraps/darwin.rb
113
+ - lib/knife-solo/bootstraps/freebsd.rb
113
114
  - lib/knife-solo/bootstraps/linux.rb
114
115
  - lib/knife-solo/bootstraps.rb
115
116
  - lib/knife-solo/info.rb
@@ -132,7 +133,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
132
133
  version: '0'
133
134
  segments:
134
135
  - 0
135
- hash: -4402118030036500865
136
+ hash: 2696735894055258276
136
137
  required_rubygems_version: !ruby/object:Gem::Requirement
137
138
  none: false
138
139
  requirements:
@@ -141,7 +142,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
141
142
  version: '0'
142
143
  segments:
143
144
  - 0
144
- hash: -4402118030036500865
145
+ hash: 2696735894055258276
145
146
  requirements: []
146
147
  rubyforge_project: nowarning
147
148
  rubygems_version: 1.8.24