Class: CapistranoKnifeSolo::Helpers

Inherits:
Object
  • Object
show all
Defined in:
lib/capistrano-knife-solo.rb

Class Method Summary collapse

Class Method Details

.chef_configObject



12
13
14
15
16
17
# File 'lib/capistrano-knife-solo.rb', line 12

def self.chef_config
  Chef::Config[:knife][:librarian] = fetch(:knife_librarian)
  Chef::Config[:knife][:berkshelf] = fetch(:knife_berkshelf)
  Chef::Config[:node_path] = fetch(:knife_node_path)
  Chef::Config.cookbook_path = fetch(:knife_cookbook_path)
end

.knife_args(host) ⇒ Object



34
35
36
37
38
39
40
41
42
43
# File 'lib/capistrano-knife-solo.rb', line 34

def self.knife_args(host)
  args = []
  if host.user
    args << "#{ host.user }@#{ host.hostname }"
  else
    args << host.hostname
  end
  args << "#{fetch(:knife_args)}" if fetch(:knife_args)
  return args
end

.knife_config(host) ⇒ Object



19
20
21
22
23
24
25
26
27
28
29
30
31
32
# File 'lib/capistrano-knife-solo.rb', line 19

def self.knife_config(host)
  ssh_options = fetch(:ssh_options, {})
  options = {}
  options[:ssh_user] = ssh_options[:user] if ssh_options[:user]
  options[:ssh_password] = ssh_options[:password] if ssh_options[:password]
  options[:ssh_port] = ssh_options[:port] if ssh_options[:port]
  options[:identity_file] = ssh_options[:keys][0] if ssh_options.fetch(:keys, [])[0]
  options[:forward_agent] = ssh_options[:forward_agent] if ssh_options[:forward_agent]
  options[:startup_script] = fetch(:knife_startup_script) if fetch(:knife_startup_script)
  options[:sudo_command] = fetch(:knife_sudo_command) if fetch(:knife_sudo_command)
  options[:host_key_verify] = fetch(:knife_host_key_verify) if fetch(:knife_host_key_verify)
  options[:run_list] = roles_to_runlist(host)
  return options
end

.roles_to_runlist(host) ⇒ Object



45
46
47
48
49
# File 'lib/capistrano-knife-solo.rb', line 45

def self.roles_to_runlist(host)
  roles = host.properties.roles.reject { |r| r.to_s.start_with?('server-') or r == :all }
  roles.map! {|r| "role[#{r}]"}
  return roles
end