Class: KnifeSuppport::Support

Inherits:
Chef::Knife
  • Object
show all
Defined in:
lib/chef/knife/support.rb

Instance Method Summary collapse

Instance Method Details

#get_configObject



132
133
134
135
136
137
138
139
140
141
# File 'lib/chef/knife/support.rb', line 132

def get_config
  msg "==== configuration ===="
  msg "=== config ==="
  pp config
  msg "=== End config ==="
  msg "=== Chef::Config ==="
  pp Chef::Config.configuration
  msg "=== End Chef::Config ==="
  msg "==== End configuration ===="
end

#knife_ssh(host) ⇒ Object



102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
# File 'lib/chef/knife/support.rb', line 102

def knife_ssh(host)
  command = if config[:use_sudo]
    "sudo chef-client -l debug"
  else
    "chef-client -l debug"
  end

  ssh = Chef::Knife::Ssh.new
  ssh.ui = ui
  ssh.name_args = [ host, command ]
  ssh.config[:ssh_user] = config[:ssh_user]
  ssh.config[:ssh_user] ||= 'root'
  ssh.config[:ssh_password] = config[:ssh_password]
  ssh.config[:ssh_port] = Chef::Config[:knife][:ssh_port] || config[:ssh_port]
  ssh.config[:identity_file] = config[:identity_file]
  ssh.config[:manual] = true
  ssh.config[:host_key_verify] = config[:host_key_verify]
  ssh.config[:on_error] = :raise
  ssh.config[:attribute] = config[:connect_attribute]
  begin
    ssh.run
  rescue Net::SSH::AuthenticationFailed
    if ssh.config[:ssh_password].nil?
      msg "Failed to authenticate #{config[:ssh_user]} - trying password auth"
      config[:ssh_password] ||= ui.ask("Enter your password: ") { |q| q.echo = false }
      knife_ssh(host)
    end
  end
end

#runObject



143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
# File 'lib/chef/knife/support.rb', line 143

def run
  unless config[:knife] or config[:nodes] or config[:roles] or config[:environments] or config[:clients] or config[:databags]
    config[:all] = true
  end
  if config[:really_all]
    config[:all] = true
    warn "The --really-all will include your data bags and data contained in them."
    confirm "Do you want to continue"
  elsif config[:databags]
    warn "The --databags will include your data bags and data contained in them."
    confirm "Do you want to continue"
  end

  get_config if config[:knife] or config[:all]
  get_nodes if config[:nodes] or config[:all]
  get_roles if config[:roles] or config[:all]
  get_environments if config[:environments] or config[:all]
  get_apiclients if config[:clients] or config[:all]
  get_databags if config[:databags] or config[:really_all]
  knife_ssh name_args.first if name_args.first
end