Class: Chef::Knife::UpdateRun
- Inherits:
-
Chef::Knife
- Object
- Chef::Knife
- Chef::Knife::UpdateRun
- Includes:
- Update
- Defined in:
- lib/chef/knife/update_run.rb
Instance Method Summary collapse
- #run ⇒ Object
- #ssh_command(version) ⇒ Object
-
#update_ssh(nodes, version) ⇒ Object
Update given nodes to specified version.
Methods included from Update
#except, included, #node_list, #only, #run_list_items, #target_version
Instance Method Details
#run ⇒ Object
73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 |
# File 'lib/chef/knife/update_run.rb', line 73 def run list = node_list compatible = run_list_items(only(list, target_version)) unknown = run_list_items(except(list, target_version)) - compatible nodes = list.inject([]) do |memo, (version, nodes)| if version != target_version nodes.each do |node| if config[:all] || node.run_list.all? { |item| items.include?(item.to_s) } memo << node end end end memo end if config[:all] && unknown.any? ui.warn("It's unknown if the following run_list items are Chef #{target_version} compatible: #{unknown.sort.join(', ')}") end ui.confirm "Are you sure you want to update #{nodes.size} nodes to chef #{target_version}" update_ssh(nodes, target_version).run end |
#ssh_command(version) ⇒ Object
116 117 118 119 120 121 122 123 124 |
# File 'lib/chef/knife/update_run.rb', line 116 def ssh_command(version) command = "gem install chef -v #{version}" if config[:use_sudo] command = "sudo #{command}" end command end |
#update_ssh(nodes, version) ⇒ Object
Update given nodes to specified version
99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 |
# File 'lib/chef/knife/update_run.rb', line 99 def update_ssh(nodes, version) fqdns = nodes.map { |node| node.fqdn }.join(' ') ssh = Chef::Knife::Ssh.new ssh.ui = ui ssh.name_args = [ fqdns, ssh_command(version) ] ssh.config[:manual] = true ssh.config[:ssh_user] = Chef::Config[:knife][:ssh_user] || config[:ssh_user] ssh.config[:ssh_password] = config[:ssh_password] ssh.config[:ssh_port] = Chef::Config[:knife][:ssh_port] || config[:ssh_port] ssh.config[:ssh_gateway] = Chef::Config[:knife][:ssh_gateway] || config[:ssh_gateway] ssh.config[:identity_file] = Chef::Config[:knife][:identity_file] || config[:identity_file] ssh.config[:host_key_verify] = Chef::Config[:knife][:host_key_verify] || config[:host_key_verify] ssh.config[:on_error] = :raise ssh end |