Class: Furnish::Provisioner::KnifeServer

Inherits:
API
  • Object
show all
Defined in:
lib/furnish/provisioners/knife_server.rb

Overview

Base class for Chef10Server and Chef11Server provisioners. The constructor and attributes in here are very important to know to use the other provisioners effectively.

Direct Known Subclasses

Chef10Server, Chef11Server

Instance Method Summary collapse

Constructor Details

#initialize(args) ⇒ KnifeServer

This is the base class constructor for Chef10Server and Chef11Server provisioners.

It takes a hash of arguments, which maps to the attributes described in this class, so go read those. If a hash is not supplied, this will raise an ArgumentError.

The minimum you will need for either provisioner is ‘ssh_user` and `ssh_password` or `ssh_identity_file`. Other defaults are provided based on the class used.



106
107
108
109
110
111
112
# File 'lib/furnish/provisioners/knife_server.rb', line 106

def initialize(args)
  super

  @node_name ||= "test-chef-server"

  check_ssh_args
end

Instance Method Details

#bootstrap_versionObject

:attr: bootstrap_version

Version of chef to bootstrap. Defaults are present in subclasses.



63
64
65
# File 'lib/furnish/provisioners/knife_server.rb', line 63

furnish_property :bootstrap_version,
"Version of chef to bootstrap. Defaults are present in subclasses.",
String

#check_ssh_argsObject

Helper to ensure that ssh arguments are passed properly.



118
119
120
121
122
123
124
125
126
# File 'lib/furnish/provisioners/knife_server.rb', line 118

def check_ssh_args
  unless ssh_user
    raise ArgumentError, "ssh_user must be supplied!"
  end

  unless ssh_password or ssh_identity_file
    raise ArgumentError, "ssh_password or ssh_identity_file must be provided"
  end
end

#config_fileObject

:attr: config_file

Path to knife.rb configuration. Yielded to following provisioners after startup succeeds.



82
83
84
# File 'lib/furnish/provisioners/knife_server.rb', line 82

furnish_property :config_file,
"Path to knife.rb configuration.",
String

#init_knife_plugin(klass, args) ⇒ Object

shim to make knife plugins as code – will be disappearing soon.



140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
# File 'lib/furnish/provisioners/knife_server.rb', line 140

def init_knife_plugin(klass, args)
  require 'stringio'

  require 'chef/application/knife'
  require 'chef/knife'
  require 'chef/config'

  Chef::Config.from_file(config_file) if config_file

  klass.options = Chef::Application::Knife.options.merge(klass.options)
  klass.load_deps
  cli = klass.new(args)
  cli.ui = Chef::Knife::UI.new(
    Furnish.logger,
    Furnish.logger,
    StringIO.new('', 'r'),
    cli.config
  )

  return cli
end

#install_testObject

:attr: install_test

Run opscode pedant after installation to test the chef server. Only works on Chef 11. Default is false.



73
74
# File 'lib/furnish/provisioners/knife_server.rb', line 73

furnish_property :install_test,
"Use opscode pedant to test the chef server after provision? Default false."

#node_nameObject

:attr: node_name

The node name of the chef server. default is “test-chef-server”.



45
46
47
# File 'lib/furnish/provisioners/knife_server.rb', line 45

furnish_property :node_name,
"The node name for the chef server. default: test-chef-server",
String

#platformObject

:attr: platform

Platform as supplied to knife-server. Defaults are present in subclasses.



54
55
56
# File 'lib/furnish/provisioners/knife_server.rb', line 54

furnish_property :platform,
"Platform as supplied to knife-server. Defaults are present in subclasses.",
String

#reportObject

Reporting facility produces the name of the group, the name of the node the chef server owns, and the platform used to build it.



196
197
198
# File 'lib/furnish/provisioners/knife_server.rb', line 196

def report
  [furnish_group_name, "node name: #{node_name}", "platform: #{platform}"]
end

#shutdown(args = { }) ⇒ Object

Teardown a Chef Server – current does nothing, as the machine is expected to be torn down instead.



188
189
190
# File 'lib/furnish/provisioners/knife_server.rb', line 188

def shutdown(args={ })
  { }
end

#ssh_identity_fileObject

:attr: ssh_identity_file

Path to a SSH private key. This or #ssh_password must be set.



36
37
38
# File 'lib/furnish/provisioners/knife_server.rb', line 36

furnish_property :ssh_identity_file,
"Path to a SSH private key. This or :ssh_password must be set.",
String

#ssh_passwordObject

:attr: ssh_password

The ssh password. This or #ssh_identity_file must be set.



27
28
29
# File 'lib/furnish/provisioners/knife_server.rb', line 27

furnish_property :ssh_password,
"The ssh password. This or :ssh_identity_file must be set.",
String

#ssh_userObject

:attr: ssh_user

The user to connect as. Required.



18
19
20
# File 'lib/furnish/provisioners/knife_server.rb', line 18

furnish_property :ssh_user,
"The user to connect as.",
String

#startup(args = {}) ⇒ Object

Provision a Chef Server with knife-server. Takes the first IP address from a set of IP addresses called :ips as its incoming argument.

Yields the ip of the chef server as :chef_server_ip, and the config file used to bootstrap it as :config_file (see #config_file)



169
170
171
172
173
174
175
176
177
178
179
180
181
182
# File 'lib/furnish/provisioners/knife_server.rb', line 169

def startup(args={})
  ip = args[:ips].first

  raise "No IP to use for the chef server" unless ip

  args = %W[--node-name #{node_name} --host #{ip} --platform #{platform} --bootstrap-version #{bootstrap_version} --ssh-user #{ssh_user}]

  args += %W[--no-test] unless install_test
  args += %W[--ssh-password #{ssh_password}]       if ssh_password
  args += %W[--identity-file #{ssh_identity_file}] if ssh_identity_file

  init_knife_plugin(Chef::Knife::ServerBootstrapStandalone, args).run
  return({ :config_file => config_file, :chef_server_ip => ip })
end