module KnifeTopo::BootstrapHelper

Node update helper for knife topo

Public Instance Methods

attributes_for_bootstrap(data) click to toggle source

for bootstrap, attributes have to include tags

# File lib/chef/knife/topo/bootstrap_helper.rb, line 60
def attributes_for_bootstrap(data)
  attrs = data['normal'] || {}
  attrs['tags'] = data['tags'] if data['tags']
  attrs
end
delete_client_node(node_name) click to toggle source
# File lib/chef/knife/topo/bootstrap_helper.rb, line 66
def delete_client_node(node_name)
  ui.info("Node #{node_name} exists and will be overwritten")
  # delete node first so vault refresh does not pick up existing node
  rest.delete("nodes/#{node_name}")
  rest.delete("clients/#{node_name}")
rescue Net::HTTPServerException => e
  raise unless e.response.code == '404'
end
run_bootstrap(data, bootstrap_args, overwrite = false) click to toggle source

Setup the bootstrap args and run the bootstrap command

# File lib/chef/knife/topo/bootstrap_helper.rb, line 28
def run_bootstrap(data, bootstrap_args, overwrite = false)
  node_name = data['name']
  args = setup_bootstrap_args(bootstrap_args, data)
  delete_client_node(node_name) if overwrite

  ui.info "Bootstrapping node #{node_name}"
  run_cmd(Chef::Knife::Bootstrap, args)
rescue StandardError => e
  raise if Chef::Config[:verbosity] == 2
  ui.warn "bootstrap of node #{node_name} exited with error"
  humanize_exception(e)
  false
end
setup_bootstrap_args(args, data) click to toggle source

rubocop:disable Metrics/AbcSize

# File lib/chef/knife/topo/bootstrap_helper.rb, line 43
def setup_bootstrap_args(args, data)
  # We need to remove the --bootstrap option, if it exists
  args -= ['--bootstrap']
  args[1] = data['ssh_host']

  # And set up the node-specific data but ONLY if defined
  args += ['-N', data['name']] if data['name']
  args += ['-E', data['chef_environment']] if data['chef_environment']
  args += ['--ssh-port', data['ssh_port']] if data['ssh_port']
  args += ['--run-list', data['run_list'].join(',')] if data['run_list']
  attrs = attributes_for_bootstrap(data)
  args += ['--json-attributes', attrs.to_json] unless attrs.empty?
  args
end