Class: Furnish::Provisioner::KnifeServer
- Inherits:
-
API
- Object
- API
- Furnish::Provisioner::KnifeServer
- 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
Instance Method Summary collapse
-
#bootstrap_version ⇒ Object
:attr: bootstrap_version.
-
#check_ssh_args ⇒ Object
Helper to ensure that ssh arguments are passed properly.
-
#config_file ⇒ Object
:attr: config_file.
-
#init_knife_plugin(klass, args) ⇒ Object
shim to make knife plugins as code – will be disappearing soon.
-
#initialize(args) ⇒ KnifeServer
constructor
This is the base class constructor for Chef10Server and Chef11Server provisioners.
-
#install_test ⇒ Object
:attr: install_test.
-
#node_name ⇒ Object
:attr: node_name.
-
#platform ⇒ Object
:attr: platform.
-
#report ⇒ Object
Reporting facility produces the name of the group, the name of the node the chef server owns, and the platform used to build it.
-
#shutdown(args = { }) ⇒ Object
Teardown a Chef Server – current does nothing, as the machine is expected to be torn down instead.
-
#ssh_identity_file ⇒ Object
:attr: ssh_identity_file.
-
#ssh_password ⇒ Object
:attr: ssh_password.
-
#ssh_user ⇒ Object
:attr: ssh_user.
-
#startup(args = {}) ⇒ Object
Provision a Chef Server with knife-server.
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_version ⇒ Object
: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_args ⇒ Object
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_file ⇒ Object
: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. = Chef::Application::Knife..merge(klass.) 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_test ⇒ Object
: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_name ⇒ Object
: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 |
#platform ⇒ Object
: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 |
#report ⇒ Object
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_file ⇒ Object
: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_password ⇒ Object
: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_user ⇒ Object
: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 |