vop-plugins 0.3.1 → 0.3.5
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/Rakefile +2 -2
- data/extended/hetzner/commands/add_ssh_key.rb +22 -0
- data/extended/hetzner/commands/disable_linux_install.rb +26 -0
- data/extended/hetzner/commands/enable_linux_install.rb +41 -0
- data/extended/hetzner/commands/hetzner_http.rb +24 -0
- data/extended/hetzner/commands/hetzner_machines.rb +11 -0
- data/extended/hetzner/commands/hetzner_server_list.rb +26 -0
- data/extended/hetzner/commands/linux_install_options.rb +29 -0
- data/extended/hetzner/commands/list_ssh_keys.rb +16 -0
- data/extended/hetzner/entities/hetzner_account.rb +9 -0
- data/extended/hetzner/hetzner.plugin +3 -0
- data/extended/hetzner_vop_0_2_x/commands/list_old_v2_vms.rb +46 -0
- data/extended/hetzner_vop_0_2_x/commands/old_libvirt_machines.rb +16 -0
- data/extended/hetzner_vop_0_2_x/commands/vop_0_2_x_ssh_options.rb +20 -0
- data/extended/hetzner_vop_0_2_x/hetzner_vop_0_2_x.plugin +5 -0
- data/extended/libvirt/commands/delete_vm.rb +32 -0
- data/extended/libvirt/commands/libvirt_config_file.rb +5 -0
- data/extended/libvirt/commands/libvirt_machines.rb +17 -0
- data/extended/libvirt/commands/libvirt_ssh_options.rb +29 -0
- data/extended/libvirt/commands/list_networks.rb +21 -0
- data/extended/libvirt/commands/list_pools.rb +20 -0
- data/extended/libvirt/commands/list_vms.rb +28 -0
- data/extended/libvirt/commands/list_vms_for_scan.rb +12 -0
- data/extended/libvirt/commands/list_vms_with_addresses.rb +20 -0
- data/extended/libvirt/commands/new_vm.rb +110 -0
- data/extended/libvirt/commands/parent.rb +10 -0
- data/extended/libvirt/commands/rename_vm.rb +34 -0
- data/extended/libvirt/commands/start_vm.rb +7 -0
- data/extended/libvirt/commands/stop_vm.rb +8 -0
- data/extended/libvirt/commands/vm_address.rb +7 -0
- data/extended/libvirt/commands/vm_addresses.rb +32 -0
- data/extended/libvirt/commands/vnc_ports.rb +32 -0
- data/extended/libvirt/helpers/helper.rb +3 -0
- data/extended/libvirt/libvirt.plugin +5 -0
- data/extended/libvirt/services/libvirt.rb +19 -0
- data/extended/libvirt_with_proxy/commands/reverse_proxy.rb +13 -0
- data/extended/libvirt_with_proxy/commands/vms_with_domains.rb +18 -0
- data/extended/libvirt_with_proxy/entities/_vms_with_domains.rbx +24 -0
- data/extended/libvirt_with_proxy/libvirt_with_proxy.plugin +1 -0
- data/extended/rails_machines/commands/rails_machines.rb +6 -0
- data/extended/rails_machines/commands/update_status.rb +38 -0
- data/extended/rails_machines/commands/write_found_machines_into_rails_db.rb.not +30 -0
- data/extended/rails_machines/rails_machines.plugin +1 -0
- data/extended/redis_cache/commands/flush_cache.rb +5 -0
- data/extended/redis_cache/commands/invalidate_cache.rb +26 -0
- data/extended/redis_cache/filters/cache_filter.rb +78 -0
- data/extended/redis_cache/helpers/cache_wrapper.rb +35 -0
- data/extended/redis_cache/redis_cache.plugin +8 -0
- data/extended/spares/commands/convert_spare.rb +93 -0
- data/extended/spares/commands/list_spares.rb +9 -0
- data/extended/spares/commands/new_vm_from_spare.rb +24 -0
- data/extended/spares/commands/post_convert_spare.rb +13 -0
- data/extended/spares/commands/prepare_spares.rb +17 -0
- data/extended/spares/commands/wait.rb +29 -0
- data/extended/spares/commands/wtf.rb +9 -0
- data/extended/spares/spares.plugin +1 -0
- data/standard/apt/apt.plugin +0 -0
- data/standard/apt/commands/add_apt_repo.rb +14 -0
- data/standard/git/commands/deploy.rb +19 -0
- data/standard/git/commands/deploy_from_git.rb +34 -0
- data/standard/git/commands/deploy_from_github.rb +12 -0
- data/standard/git/commands/git_clone.rb +7 -0
- data/standard/git/commands/git_clone_web.rb +22 -0
- data/standard/git/git.plugin +0 -0
- data/standard/linux/commands/append_to_file.rb +14 -0
- data/standard/linux/commands/chmod.rb +7 -0
- data/standard/linux/commands/curl.rb +15 -0
- data/standard/linux/commands/current_user.rb +5 -0
- data/standard/linux/commands/distro.rb +2 -1
- data/standard/linux/commands/download_file.rb +6 -6
- data/standard/linux/commands/external_ip.rb +15 -0
- data/standard/linux/commands/file_exists.rb +7 -0
- data/standard/linux/commands/home.rb +7 -0
- data/standard/linux/commands/hostname.rb +5 -0
- data/standard/linux/commands/internal_ip.rb +14 -0
- data/standard/linux/commands/ipaddress.rb +10 -0
- data/standard/linux/commands/list_files.rb +8 -6
- data/standard/linux/commands/list_ip_addresses.rb +22 -0
- data/standard/linux/commands/listen_ports.rb +3 -2
- data/standard/linux/commands/maybe_sudo.rb +8 -0
- data/standard/linux/commands/mkdirs.rb +12 -0
- data/standard/linux/commands/processes.rb +8 -6
- data/standard/linux/commands/processes_like.rb +7 -7
- data/standard/linux/commands/processes_top.rb +23 -0
- data/standard/linux/commands/processes_top_cpu.rb +8 -0
- data/standard/linux/commands/processes_top_mem.rb +8 -0
- data/standard/linux/commands/read_file.rb +7 -2
- data/standard/linux/commands/replace_in_file.rb +22 -0
- data/standard/linux/commands/set_hostname.rb +36 -0
- data/standard/linux/commands/update_hosts_file.rb +27 -0
- data/standard/linux/commands/write_file.rb +8 -21
- data/standard/linux/linux.plugin +1 -2
- data/standard/machines/commands/delete_old_machines.rb +17 -0
- data/standard/machines/commands/localhost.rb +7 -2
- data/standard/machines/commands/localhost_ssh_options.rb +9 -0
- data/standard/machines/commands/new_machine.rb +24 -0
- data/standard/machines/commands/new_vm_from_scratch.rb +25 -0
- data/standard/machines/commands/old_machines.rb +6 -0
- data/standard/machines/commands/select_machine.rb +4 -5
- data/standard/machines/entities/machine.rb +12 -0
- data/standard/machines/machines.plugin +1 -1
- data/standard/redis_machines/commands/installation_status.rb +10 -0
- data/standard/redis_machines/commands/track_installation_status.rb +13 -0
- data/standard/redis_machines/redis_machines.plugin +3 -0
- data/standard/rpm/commands/list_rpm_packages.rb +24 -0
- data/standard/rpm/rpm.plugin +1 -0
- data/standard/scanner/commands/clean_metadata.rb +8 -0
- data/standard/scanner/commands/fresh_ssh_test.rb +6 -0
- data/standard/scanner/commands/inspect_async.rb +6 -0
- data/standard/scanner/commands/inspect_machine.rb +42 -0
- data/standard/scanner/commands/machines_found.rb +35 -0
- data/standard/scanner/commands/metadata.rb +9 -0
- data/standard/scanner/commands/redis_machines.rb +11 -0
- data/standard/scanner/commands/scan.rb +5 -0
- data/standard/scanner/commands/scan_host.rb +7 -0
- data/standard/scanner/commands/scan_machines.rb +11 -0
- data/standard/scanner/commands/trigger_ssh_test.rb +8 -0
- data/standard/scanner/scanner.plugin +5 -0
- data/standard/services/commands/describe_service.rb +7 -0
- data/standard/services/commands/describe_service_installation.rb +13 -0
- data/standard/services/commands/detect_services.rb +34 -0
- data/standard/services/commands/install_service.rb +134 -0
- data/standard/services/commands/list_known_services.rb +14 -0
- data/standard/services/commands/load_plugin_services.rb +17 -0
- data/standard/services/entities/service.rb +3 -0
- data/standard/services/helpers/service.rb +31 -0
- data/standard/services/helpers/service_loader.rb +50 -0
- data/standard/services/helpers/service_syntax.rb +126 -0
- data/standard/services/services.plugin +9 -0
- data/standard/ssh/commands/clean_known_host.rb +11 -0
- data/standard/ssh/commands/clear_ssh_cache.rb +9 -0
- data/standard/ssh/commands/get_ssh_connection.rb +36 -0
- data/standard/ssh/commands/scp_down.rb +9 -0
- data/standard/ssh/commands/scp_up.rb +9 -0
- data/standard/ssh/commands/ssh.rb +20 -0
- data/standard/ssh/commands/ssh_call.rb +98 -0
- data/standard/ssh/commands/ssh_connection.rb +55 -0
- data/standard/ssh/commands/ssh_extended.rb +6 -0
- data/standard/ssh/commands/ssh_options.rb +12 -0
- data/standard/ssh/commands/sudo.rb +12 -0
- data/standard/ssh/commands/test_ssh.rb +43 -0
- data/standard/{linux → ssh}/helpers/regex.rb +0 -0
- data/standard/ssh/ssh.plugin +10 -0
- data/standard/ssh_keys/commands/add_authorized_key.rb +14 -0
- data/standard/ssh_keys/commands/disable_ssh_key_check.rb +11 -0
- data/standard/ssh_keys/commands/generate_keypair.rb +17 -0
- data/standard/ssh_keys/ssh_keys.plugin +0 -0
- data/standard/systemd/commands/disable_systemd_service.rb +8 -0
- data/standard/systemd/commands/enable_systemd_service.rb +8 -0
- data/standard/systemd/commands/list_systemd_services.rb +23 -0
- data/standard/systemd/commands/start_systemd_service.rb +6 -0
- data/standard/systemd/commands/stop_systemd_service.rb +6 -0
- data/standard/systemd/commands/systemd_service_status.rb +6 -0
- data/standard/systemd/commands/write_systemd_config.rb +16 -0
- data/standard/systemd/helpers/param_service.rb +7 -0
- data/standard/systemd/systemd.plugin +0 -0
- data/standard/systemd/templates/systemd_service.erb +11 -0
- data/standard/templates/commands/read_template.rb +8 -0
- data/standard/templates/commands/write_template.rb +37 -0
- data/standard/templates/templates.plugin +3 -0
- data/vop-plugins.gemspec +6 -7
- metadata +156 -55
- data/Gemfile +0 -3
- data/Gemfile.lock +0 -68
- data/standard/debian-iso/commands/fetch_debian_iso.rb +0 -3
- data/standard/debian-iso/commands/fetch_ubuntu_iso.rb +0 -22
- data/standard/debian-iso/commands/list_isos.rb +0 -6
- data/standard/debian-iso/commands/rebuild_debian_iso.rb +0 -40
- data/standard/debian-iso/debian-iso.plugin +0 -2
- data/standard/debian-iso/files/rebuild-debian-iso +0 -74
- data/standard/debian-iso/templates/preseed.cfg +0 -45
- data/standard/libvirt/commands/delete_vm.rb +0 -16
- data/standard/libvirt/commands/list_local_vms.rb +0 -4
- data/standard/libvirt/commands/list_vms.rb +0 -15
- data/standard/libvirt/commands/new_vm.rb +0 -61
- data/standard/libvirt/commands/start_vm.rb +0 -6
- data/standard/libvirt/commands/stop_vm.rb +0 -6
- data/standard/libvirt/libvirt.plugin +0 -2
- data/standard/linux/commands/disk_free.rb +0 -26
- data/standard/linux/commands/disk_used.rb +0 -4
- data/standard/linux/commands/find.rb +0 -15
- data/standard/linux/commands/mkdir.rb +0 -6
- data/standard/linux/todo +0 -2
- data/standard/machines/commands/list_machines_old.rb +0 -7
- data/standard/machines/commands/machine.rb +0 -3
- data/standard/machines/commands/run_command.rb +0 -10
- data/standard/plugin.vop +0 -1
- data/standard/services/loader/service.rb +0 -3
- data/standard/vagrant/commands/vagrant_global_status.rb +0 -32
- data/standard/vagrant/vagrant.plugin +0 -1
- data/standard/working_copies/commands/git_working_copies.rb +0 -11
- data/standard/working_copies/commands/list_project_folders.rb +0 -8
- data/standard/working_copies/commands/working_copy.rb +0 -3
- data/standard/working_copies/working_copies.plugin +0 -1
@@ -0,0 +1,36 @@
|
|
1
|
+
require "timeout"
|
2
|
+
|
3
|
+
param! :machine
|
4
|
+
param "force", default: false
|
5
|
+
param "timeout", description: "in seconds", default: 10
|
6
|
+
|
7
|
+
run do |machine, force|
|
8
|
+
seconds = seconds.to_i
|
9
|
+
connection = nil
|
10
|
+
begin
|
11
|
+
Timeout::timeout(seconds) do
|
12
|
+
tried_with_force = false
|
13
|
+
done = false
|
14
|
+
until tried_with_force || done do
|
15
|
+
connection = machine.ssh_connection(force: force)
|
16
|
+
tried_with_force = true if force
|
17
|
+
begin
|
18
|
+
connection.exec! "hostname"
|
19
|
+
done = true
|
20
|
+
rescue => e
|
21
|
+
if force
|
22
|
+
state = force ? "fresh " : ""
|
23
|
+
raise "problem while testing #{state}ssh connection to #{machine.name} : #{e.message}"
|
24
|
+
else
|
25
|
+
$logger.debug "SSH check failed (#{e.message}), requesting fresh connection to #{machine.name}"
|
26
|
+
force = true
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
31
|
+
rescue => detail
|
32
|
+
raise "timed out while connecting to #{machine.name} : #{detail.message}"
|
33
|
+
end
|
34
|
+
|
35
|
+
connection
|
36
|
+
end
|
@@ -0,0 +1,9 @@
|
|
1
|
+
param! :machine
|
2
|
+
param! "remote_path"
|
3
|
+
param! "local_path"
|
4
|
+
|
5
|
+
run do |machine, remote_path, local_path|
|
6
|
+
ssh = machine.ssh_connection(force: true, dont_cache: true)
|
7
|
+
$logger.debug "[#{machine.name}] scp #{remote_path} -> #{local_path}"
|
8
|
+
ssh.scp.download! remote_path, local_path
|
9
|
+
end
|
@@ -0,0 +1,9 @@
|
|
1
|
+
param! :machine
|
2
|
+
param! "local_path"
|
3
|
+
param! "remote_path"
|
4
|
+
|
5
|
+
run do |machine, local_path, remote_path|
|
6
|
+
ssh = machine.ssh_connection(force: true, dont_cache: true)
|
7
|
+
$logger.debug "[#{machine.name}] scp #{local_path} -> #{remote_path}"
|
8
|
+
ssh.scp.upload! local_path, remote_path
|
9
|
+
end
|
@@ -0,0 +1,20 @@
|
|
1
|
+
# TODO params_as ssh_call ?
|
2
|
+
|
3
|
+
param! "machine"
|
4
|
+
param! "command", :default_param => true
|
5
|
+
|
6
|
+
param "request_pty", :default => false
|
7
|
+
|
8
|
+
param "show_output", default: false
|
9
|
+
|
10
|
+
run do |params|
|
11
|
+
result = @op.ssh_call(params)
|
12
|
+
|
13
|
+
unless result["result_code"].to_i == 0
|
14
|
+
exception_with_backtrace = StandardError.new("SSH result code not zero")
|
15
|
+
exception_with_backtrace.set_backtrace(result["combined"])
|
16
|
+
raise exception_with_backtrace
|
17
|
+
end
|
18
|
+
|
19
|
+
result["combined"]
|
20
|
+
end
|
@@ -0,0 +1,98 @@
|
|
1
|
+
param! :machine
|
2
|
+
|
3
|
+
param! "command", default_param: true
|
4
|
+
|
5
|
+
param "on_data", default: nil
|
6
|
+
param "on_stderr", default: nil
|
7
|
+
param "request_pty", default: false
|
8
|
+
|
9
|
+
param "show_output", default: false
|
10
|
+
|
11
|
+
run do |machine, params, show_output|
|
12
|
+
connection = machine.get_ssh_connection
|
13
|
+
|
14
|
+
$logger.debug "request_pty ? #{params["request_pty"]}"
|
15
|
+
|
16
|
+
stdout = ""
|
17
|
+
stderr = ""
|
18
|
+
combined = ""
|
19
|
+
result_code = nil
|
20
|
+
connection.open_channel do |channel|
|
21
|
+
if params.has_key?('request_pty') && params['request_pty'].to_s == "true"
|
22
|
+
$logger.debug "requesting pty"
|
23
|
+
channel.request_pty do |ch, success|
|
24
|
+
unless success
|
25
|
+
raise Exception.new("could not obtain pty!")
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
29
|
+
|
30
|
+
channel.on_request('exit-status') do |c, data|
|
31
|
+
result_code = data.read_long
|
32
|
+
$logger.debug "read exit code : #{result_code}"
|
33
|
+
end
|
34
|
+
|
35
|
+
params["on_data"] ||= lambda do |c, data|
|
36
|
+
stdout += data
|
37
|
+
combined += data
|
38
|
+
|
39
|
+
puts data if show_output
|
40
|
+
$logger.debug "got data on STDOUT #{data}"
|
41
|
+
end
|
42
|
+
channel.on_data do |c, data|
|
43
|
+
params["on_data"].call(c, data)
|
44
|
+
end
|
45
|
+
|
46
|
+
params["on_stderr"] ||= lambda do |c, data|
|
47
|
+
stderr += data
|
48
|
+
combined += data
|
49
|
+
|
50
|
+
puts data if show_output
|
51
|
+
$logger.debug "got data on STDERR #{data}"
|
52
|
+
end
|
53
|
+
channel.on_extended_data do |c, type, data|
|
54
|
+
params["on_stderr"].call(c, data)
|
55
|
+
end
|
56
|
+
|
57
|
+
#channel.on_close { $logger.debug "done" }
|
58
|
+
|
59
|
+
command = params["command"]
|
60
|
+
|
61
|
+
channel.exec(command) do |ch, success|
|
62
|
+
if success
|
63
|
+
$logger.debug "executed command successfully."
|
64
|
+
else
|
65
|
+
$logger.warn "could not execute command #{command}"
|
66
|
+
raise RuntimeError.new("could not execute #{command}")
|
67
|
+
end
|
68
|
+
end
|
69
|
+
end
|
70
|
+
|
71
|
+
if params.has_key?('dont_loop') and params['dont_loop'] == "true"
|
72
|
+
$logger.debug "not waiting for process to finish"
|
73
|
+
{
|
74
|
+
"combined" => combined,
|
75
|
+
"stdout" => stdout,
|
76
|
+
"stderr" => stderr,
|
77
|
+
"connection" => connection
|
78
|
+
}
|
79
|
+
else
|
80
|
+
connection.loop
|
81
|
+
|
82
|
+
lines = params["command"].lines
|
83
|
+
first_line = lines.first
|
84
|
+
short_command = first_line.strip[0..49]
|
85
|
+
if lines.size > 1 || first_line.size > 50
|
86
|
+
short_command += "[...]"
|
87
|
+
end
|
88
|
+
$logger.info "ssh [#{params["machine"]}] #{first_line}, result : #{result_code}"
|
89
|
+
$logger.debug "full command : #{params["command"].lines.join("\n")}"
|
90
|
+
|
91
|
+
{
|
92
|
+
"combined" => combined,
|
93
|
+
"stdout" => stdout,
|
94
|
+
"stderr" => stderr,
|
95
|
+
"result_code" => result_code
|
96
|
+
}
|
97
|
+
end
|
98
|
+
end
|
@@ -0,0 +1,55 @@
|
|
1
|
+
param! :machine
|
2
|
+
param "force", default: false
|
3
|
+
param "dont_cache", default: false
|
4
|
+
|
5
|
+
run do |plugin, machine, force, dont_cache|
|
6
|
+
ssh_opts = @op.ssh_options("machine" => machine.name)
|
7
|
+
$logger.debug "ssh options for #{machine.name} : #{ssh_opts.pretty_inspect}"
|
8
|
+
if ssh_opts.nil? || ssh_opts.empty?
|
9
|
+
raise "no SSH options for machine #{machine.name}"
|
10
|
+
end
|
11
|
+
|
12
|
+
host = ssh_opts["host_or_ip"] || machine.name
|
13
|
+
user = ssh_opts["user"] || ENV["USER"]
|
14
|
+
port = ssh_opts["port"] || 22
|
15
|
+
options = ssh_opts.has_key?("options") ? ssh_opts["options"] : {}
|
16
|
+
|
17
|
+
options[:port] = port
|
18
|
+
|
19
|
+
if ssh_opts.has_key? "password"
|
20
|
+
options[:password] = ssh_opts["password"]
|
21
|
+
end
|
22
|
+
|
23
|
+
key = "#{user}@#{host}:#{port}"
|
24
|
+
$logger.debug("ssh connection to #{key}")
|
25
|
+
|
26
|
+
pool = plugin.state[:ssh_connections]
|
27
|
+
connection = nil
|
28
|
+
connection = pool[key] unless force
|
29
|
+
|
30
|
+
if connection.nil?
|
31
|
+
if ssh_opts["jump_host"]
|
32
|
+
jump_host_name = ssh_opts["jump_host"]
|
33
|
+
jump_host = @op.ssh_options(jump_host_name)
|
34
|
+
$logger.debug "using jump host #{jump_host_name}"
|
35
|
+
jump_pool = plugin.state[:jump_connections]
|
36
|
+
jump_target = "#{jump_host["user"]}@#{jump_host["host_or_ip"]}"
|
37
|
+
cached_jump_host = jump_pool[jump_target] unless force
|
38
|
+
proxy = if cached_jump_host
|
39
|
+
cached_jump_host
|
40
|
+
else
|
41
|
+
$logger.debug "new connection to jump host #{jump_target}"
|
42
|
+
new_proxy = Net::SSH::Proxy::Jump.new(jump_target)
|
43
|
+
jump_pool[jump_target] = new_proxy unless dont_cache
|
44
|
+
new_proxy
|
45
|
+
end
|
46
|
+
options[:proxy] = proxy
|
47
|
+
end
|
48
|
+
|
49
|
+
$logger.debug "new SSH connection as #{user} to #{host} (#{options.pretty_inspect})"
|
50
|
+
connection = Net::SSH.start(host, user, options)
|
51
|
+
pool[key] = connection unless dont_cache #unless ssh_opts["jump_host"]
|
52
|
+
end
|
53
|
+
|
54
|
+
connection
|
55
|
+
end
|
@@ -0,0 +1,12 @@
|
|
1
|
+
param! :machine
|
2
|
+
param! "command", default_param: true
|
3
|
+
|
4
|
+
run do |machine, params|
|
5
|
+
sudo_options = ""
|
6
|
+
distro = machine.distro.split("_").first
|
7
|
+
if %w|debian ubuntu|.include? distro
|
8
|
+
sudo_options += "--non-interactive"
|
9
|
+
end
|
10
|
+
|
11
|
+
machine.ssh("command" => "sudo #{sudo_options} #{params["command"]}", "request_pty" => true)
|
12
|
+
end
|
@@ -0,0 +1,43 @@
|
|
1
|
+
require "timeout"
|
2
|
+
|
3
|
+
param! "machine"
|
4
|
+
param "seconds", default: 10
|
5
|
+
|
6
|
+
read_only
|
7
|
+
|
8
|
+
KNOWN_MESSAGES = [
|
9
|
+
"execution expired",
|
10
|
+
"No route to host",
|
11
|
+
"Connection refused",
|
12
|
+
"closed stream",
|
13
|
+
"getaddrinfo: Name or service not known",
|
14
|
+
"Broken pipe",
|
15
|
+
"timed out while connecting to"
|
16
|
+
]
|
17
|
+
run do |params, seconds|
|
18
|
+
result = nil
|
19
|
+
|
20
|
+
seconds = seconds.to_i
|
21
|
+
begin
|
22
|
+
Timeout::timeout(seconds) do
|
23
|
+
@op.ssh("machine" => params["machine"], "command" => "id")
|
24
|
+
result = true
|
25
|
+
end
|
26
|
+
rescue => detail
|
27
|
+
matched = nil
|
28
|
+
KNOWN_MESSAGES.each do |text|
|
29
|
+
pattern = Regexp.new(text)
|
30
|
+
if matched = pattern.match(detail.message)
|
31
|
+
$logger.debug "known error #{pattern}"
|
32
|
+
result = false
|
33
|
+
break
|
34
|
+
end
|
35
|
+
end
|
36
|
+
unless matched
|
37
|
+
$logger.warn "unknown error : #{detail.message}"
|
38
|
+
raise detail
|
39
|
+
end
|
40
|
+
end
|
41
|
+
|
42
|
+
result
|
43
|
+
end
|
File without changes
|
@@ -0,0 +1,14 @@
|
|
1
|
+
description "adds a public key to the SSH directory of a user on a machine so that it is authorized to login"
|
2
|
+
|
3
|
+
param :machine
|
4
|
+
param! "public_key", description: "the public key that should be added", :default_param => true
|
5
|
+
|
6
|
+
run do |machine, public_key|
|
7
|
+
machine.mkdirs("dir" => ".ssh", "permissions" => "700")
|
8
|
+
|
9
|
+
unless machine.file_exists(".ssh/authorized_keys")
|
10
|
+
machine.ssh("touch .ssh/authorized_keys")
|
11
|
+
machine.chmod("file" => ".ssh/authorized_keys", "permissions" => "600")
|
12
|
+
end
|
13
|
+
machine.ssh("echo \"#{public_key}\" >> .ssh/authorized_keys")
|
14
|
+
end
|
@@ -0,0 +1,11 @@
|
|
1
|
+
description "modifies the local ssh configuration so that no host key checks are performed"
|
2
|
+
|
3
|
+
param :machine
|
4
|
+
param "home_dir", "the home directory into which the ssh configuration should be written"
|
5
|
+
|
6
|
+
run do |machine, params|
|
7
|
+
params["home_dir"] ||= machine.home
|
8
|
+
file_name = params["home_dir"] + "/.ssh/config"
|
9
|
+
|
10
|
+
machine.append_to_file("file_name" => file_name, "content" => 'StrictHostKeyChecking no')
|
11
|
+
end
|
@@ -0,0 +1,17 @@
|
|
1
|
+
description "generates a new key pair on the selected machine"
|
2
|
+
#
|
3
|
+
param :machine
|
4
|
+
param "ssh_dir", "the ssh configuration directory (defaults to $HOME/.ssh)"
|
5
|
+
|
6
|
+
run do |machine, params|
|
7
|
+
ssh_dir = params.has_key?("ssh_dir") ? params["ssh_dir"] : ".ssh"
|
8
|
+
private_keyfile = ssh_dir + "/id_rsa"
|
9
|
+
|
10
|
+
unless machine.file_exists(private_keyfile)
|
11
|
+
machine.mkdirs ssh_dir
|
12
|
+
machine.ssh "ssh-keygen -N '' -f #{private_keyfile}"
|
13
|
+
machine.ssh "cd #{ssh_dir} && cat id_rsa.pub >> authorized_keys"
|
14
|
+
end
|
15
|
+
|
16
|
+
#machine.file_exists! private_keyfile
|
17
|
+
end
|
File without changes
|
@@ -0,0 +1,23 @@
|
|
1
|
+
param! :machine
|
2
|
+
|
3
|
+
read_only
|
4
|
+
|
5
|
+
run do |machine|
|
6
|
+
result = []
|
7
|
+
|
8
|
+
input = machine.ssh "systemctl list-unit-files --type=service"
|
9
|
+
input.split("\n").each_with_index do |line, idx|
|
10
|
+
# skip one header line
|
11
|
+
next if idx == 0
|
12
|
+
|
13
|
+
# stop at the first empty line
|
14
|
+
break if line =~ /^$/
|
15
|
+
|
16
|
+
parts = line.split
|
17
|
+
result << {
|
18
|
+
name: parts.first,
|
19
|
+
state: parts.last
|
20
|
+
}
|
21
|
+
end
|
22
|
+
result
|
23
|
+
end
|