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,12 @@
|
|
1
|
+
param! :machine
|
2
|
+
param! "github_project", description: "full name (author/repo) of the project that should be checked out"
|
3
|
+
param! "domain", multi: true, description: "the domain on which the project should be deployed"
|
4
|
+
param "subfolder", description: "folder inside git checkout that should be published (as web root)"
|
5
|
+
|
6
|
+
contribute to: "deploy" do |params, github_project|
|
7
|
+
params.delete("github_project")
|
8
|
+
|
9
|
+
@op.deploy_from_git(
|
10
|
+
params.merge("git_url" => "https://github.com/#{github_project}.git")
|
11
|
+
)
|
12
|
+
end
|
@@ -0,0 +1,22 @@
|
|
1
|
+
param! :machine
|
2
|
+
param! "url", default_param: true
|
3
|
+
|
4
|
+
run do |machine, url|
|
5
|
+
project_name = nil
|
6
|
+
if /\/([^\/]+)\.git$/.match(url)
|
7
|
+
project_name = $1
|
8
|
+
end
|
9
|
+
if project_name.nil?
|
10
|
+
raise "could not determine project_name from Git URL: unexpected format #{url}"
|
11
|
+
end
|
12
|
+
|
13
|
+
dir = "/var/www/#{project_name}"
|
14
|
+
unless machine.file_exists(dir)
|
15
|
+
machine.sudo("mkdir #{dir}")
|
16
|
+
# TODO hardcoded marvin
|
17
|
+
machine.sudo("chown marvin:www-data #{dir}")
|
18
|
+
machine.git_clone("url" => url, "dir" => dir)
|
19
|
+
end
|
20
|
+
|
21
|
+
dir
|
22
|
+
end
|
File without changes
|
@@ -0,0 +1,14 @@
|
|
1
|
+
description "appends content to a file (without locking, be careful)"
|
2
|
+
|
3
|
+
param! :machine
|
4
|
+
param! "file_name", "the target file to append content to. will be created if it doesn't exist."
|
5
|
+
param! "content", "the content to add to the file"
|
6
|
+
|
7
|
+
run do |machine, file_name, content|
|
8
|
+
old_content = machine.file_exists(file_name) ?
|
9
|
+
machine.read_file(file_name) : nil
|
10
|
+
|
11
|
+
new_content = [ old_content, content ].join("\n")
|
12
|
+
|
13
|
+
machine.write_file("file_name" => file_name, "content" => new_content)
|
14
|
+
end
|
@@ -0,0 +1,15 @@
|
|
1
|
+
param! :machine
|
2
|
+
param! "url", default_param: true
|
3
|
+
|
4
|
+
run do |machine, url|
|
5
|
+
has_curl = machine.ssh("which curl")
|
6
|
+
|
7
|
+
$logger.debug "has_curl: #{has_curl}"
|
8
|
+
raise "no curl" unless has_curl
|
9
|
+
|
10
|
+
command = "curl --location"
|
11
|
+
command += " '#{url}'"
|
12
|
+
|
13
|
+
$logger.debug "command: #{command}"
|
14
|
+
machine.ssh(command)
|
15
|
+
end
|
@@ -2,13 +2,14 @@ description "tries to return a meaningful string for the linux distribution runn
|
|
2
2
|
|
3
3
|
param! :machine
|
4
4
|
|
5
|
-
|
5
|
+
read_only
|
6
6
|
|
7
7
|
run do |machine, params|
|
8
8
|
input = machine.ssh("cat /etc/issue")
|
9
9
|
|
10
10
|
input.strip!
|
11
11
|
first_line = input.split("\n").first
|
12
|
+
|
12
13
|
result = 'unknown'
|
13
14
|
if (matched = /SUSE\s+Linux\s+Enterprise\s+Server\s(\d+)\s+(SP\d+)?/.match(first_line))
|
14
15
|
result = 'sles_' + matched.captures[0] + ' ' + matched.captures[1]
|
@@ -1,17 +1,17 @@
|
|
1
|
-
param!
|
2
|
-
param!
|
3
|
-
param!
|
1
|
+
param! :machine
|
2
|
+
param! "url"
|
3
|
+
param! "file"
|
4
4
|
|
5
5
|
run do |machine, url, file|
|
6
6
|
has_curl = machine.ssh("which curl")
|
7
7
|
|
8
|
-
|
8
|
+
$logger.debug "has_curl: #{has_curl}"
|
9
9
|
raise "no curl" unless has_curl
|
10
10
|
|
11
11
|
command = "curl --silent --location"
|
12
12
|
command += " --create-dirs -o #{file}"
|
13
|
-
command += " #{url}"
|
13
|
+
command += " '#{url}'"
|
14
14
|
|
15
|
-
|
15
|
+
$logger.debug "command: #{command}"
|
16
16
|
machine.ssh(command)
|
17
17
|
end
|
@@ -0,0 +1,15 @@
|
|
1
|
+
param! :machine
|
2
|
+
param "internal_prefix", default: "192.168"
|
3
|
+
|
4
|
+
run do |machine, internal_prefix|
|
5
|
+
unless internal_prefix.end_with? "."
|
6
|
+
internal_prefix += "."
|
7
|
+
end
|
8
|
+
escaped_prefix = internal_prefix.gsub!(".", "\\.")
|
9
|
+
|
10
|
+
# TODO make ipv4 vs ipv6 configurable
|
11
|
+
input = machine.ssh("ip addr | grep -v '#{internal_prefix}' | grep inet | grep -v inet6 | grep -v '127.0.0.1'")
|
12
|
+
if input =~ /inet\s+([\d\.]+)(?:\/(\d+))?/
|
13
|
+
$1
|
14
|
+
end
|
15
|
+
end
|
@@ -0,0 +1,14 @@
|
|
1
|
+
param! :machine
|
2
|
+
param "prefix", default: "192.168"
|
3
|
+
|
4
|
+
run do |machine, prefix|
|
5
|
+
unless prefix.end_with? "."
|
6
|
+
prefix += "."
|
7
|
+
end
|
8
|
+
escaped_prefix = prefix.gsub!(".", "\\.")
|
9
|
+
# TODO we could have more than one internal IP, right?
|
10
|
+
input = machine.ssh("ip addr | grep #{prefix}")
|
11
|
+
if input =~ /inet\s+(#{prefix}\d+\.\d+)/
|
12
|
+
$1
|
13
|
+
end
|
14
|
+
end
|
@@ -0,0 +1,10 @@
|
|
1
|
+
description "returns the host's ip addresses (currently this means eth0)"
|
2
|
+
|
3
|
+
param! :machine
|
4
|
+
param "interface", description: "name of the interface", default_value: "eth0"
|
5
|
+
|
6
|
+
read_only
|
7
|
+
|
8
|
+
run do |machine, params|
|
9
|
+
machine.list_ip_addresses('device' => params['interface']).first["address"]
|
10
|
+
end
|
@@ -1,17 +1,19 @@
|
|
1
|
-
param!
|
2
|
-
param!
|
1
|
+
param! :machine
|
2
|
+
param! "dir", default_param: true
|
3
3
|
|
4
|
-
|
4
|
+
read_only
|
5
|
+
|
6
|
+
show columns: %w|name owner group permissions size timestamp|
|
5
7
|
|
6
8
|
run do |machine, dir|
|
7
9
|
ssh_regex(machine, "ls -l --full-time #{dir}",
|
8
10
|
# drwxrwxr-x 3 philipp philipp 4096 2016-01-16 04:16:24.621111156 +0100 lib
|
9
11
|
/(\S+)\s+(\d+)\s+(\S+)\s+(\S+)\s+(\d+)\s+([\d-]+)\s+([\d:]+)\.\d+\s+(\+\d+)\s+(.+)$/,
|
10
|
-
%
|
12
|
+
%w|permissions links owner group size date time time_zone name|,
|
11
13
|
{
|
12
14
|
:post_process => lambda { |parsed|
|
13
|
-
date, time, zone = parsed.delete(
|
14
|
-
parsed[
|
15
|
+
date, time, zone = parsed.delete("date"), parsed.delete("time"), parsed.delete("time_zone")
|
16
|
+
parsed["timestamp"] = "#{date} #{time} #{zone}"
|
15
17
|
parsed
|
16
18
|
}
|
17
19
|
}
|
@@ -0,0 +1,22 @@
|
|
1
|
+
param :machine
|
2
|
+
param "device"
|
3
|
+
param "filter"
|
4
|
+
|
5
|
+
show columns: [ :address, :netmask ]
|
6
|
+
|
7
|
+
run do |machine, params|
|
8
|
+
dev_filter = params.has_key?("device") ? "show #{params["device"]}" : ''
|
9
|
+
|
10
|
+
result = []
|
11
|
+
lines = machine.sudo("ip addr #{dev_filter}").split("\n")
|
12
|
+
lines.each do |line|
|
13
|
+
line.chomp! and line.strip!
|
14
|
+
# TODO handle inet6
|
15
|
+
next unless matched = /inet\s([\d\.]+)(?:\/(\d+))?/.match(line)
|
16
|
+
result << {
|
17
|
+
"address" => $1,
|
18
|
+
"netmask" => $2
|
19
|
+
}
|
20
|
+
end
|
21
|
+
result
|
22
|
+
end
|
@@ -1,6 +1,8 @@
|
|
1
|
-
param!
|
1
|
+
param! :machine
|
2
2
|
|
3
|
-
show columns: %
|
3
|
+
show columns: %w|pid command_short|
|
4
|
+
|
5
|
+
read_only
|
4
6
|
|
5
7
|
run do |params, machine|
|
6
8
|
input = machine.ssh("ps aux")
|
@@ -10,10 +12,10 @@ run do |params, machine|
|
|
10
12
|
(user, pid, cpu, mem, vsz, rss, tty, stat, start, time) = parts[0..9]
|
11
13
|
command = parts[10..parts.length-1].join(" ")
|
12
14
|
{
|
13
|
-
pid
|
14
|
-
command
|
15
|
-
command_short
|
16
|
-
user
|
15
|
+
"pid" => pid,
|
16
|
+
"command" => command,
|
17
|
+
"command_short" => command[0..79],
|
18
|
+
"user" => user
|
17
19
|
}
|
18
20
|
end
|
19
21
|
end
|
@@ -1,11 +1,11 @@
|
|
1
|
-
param!
|
2
|
-
param! "
|
1
|
+
param! :machine
|
2
|
+
param! "regex", default_param: true
|
3
3
|
|
4
|
-
show columns: %
|
4
|
+
show columns: %w|pid command|
|
5
5
|
|
6
|
-
run do |
|
7
|
-
|
8
|
-
|
9
|
-
|
6
|
+
run do |machine, regex|
|
7
|
+
the_regex = /#{Regexp.escape(regex)}/
|
8
|
+
machine.processes.select do |process|
|
9
|
+
the_regex.match(process["command"])
|
10
10
|
end
|
11
11
|
end
|
@@ -0,0 +1,23 @@
|
|
1
|
+
param! :machine
|
2
|
+
param! "sort_column"
|
3
|
+
param "count", default: 10
|
4
|
+
|
5
|
+
show sort: false
|
6
|
+
|
7
|
+
run do |machine, sort_column, count|
|
8
|
+
result = ssh_regex(machine, "ps -eo pid,args,%cpu,%mem --sort -#{sort_column}",
|
9
|
+
# PID COMMAND %CPU %MEM
|
10
|
+
# 2572 ng 60.4 12.1
|
11
|
+
/^\s*(\d+)\s+(.+)\s+([\d\.]+)\s+([\d\.]+)$/,
|
12
|
+
%w|pid command cpu mem|
|
13
|
+
)
|
14
|
+
|
15
|
+
# TODO would be nifty to auto-detect numbers (then we wouldn't have to .to_i here)
|
16
|
+
count = count.to_i
|
17
|
+
if count > 0
|
18
|
+
last_idx = count -1
|
19
|
+
result = result[0..last_idx]
|
20
|
+
end
|
21
|
+
|
22
|
+
result
|
23
|
+
end
|
@@ -0,0 +1,22 @@
|
|
1
|
+
description "calls 'sed' to replace a pattern in a file. see man sed"
|
2
|
+
|
3
|
+
param :machine
|
4
|
+
param! "file_name", "the file to work with"
|
5
|
+
param! "source", "the source pattern that should be replaced"
|
6
|
+
param! "target", "the replacement string"
|
7
|
+
param "sudo", default: false
|
8
|
+
|
9
|
+
run do |machine, params, sudo|
|
10
|
+
source = params["source"].gsub('/', '\/')
|
11
|
+
target = params["target"].gsub('/', '\/')
|
12
|
+
sed_cmd = "sed -i -e 's/#{source}/#{target}/g' #{params["file_name"]}"
|
13
|
+
if sudo
|
14
|
+
machine.sudo sed_cmd
|
15
|
+
else
|
16
|
+
machine.ssh sed_cmd
|
17
|
+
end
|
18
|
+
# TODO this hangs when sudo=true
|
19
|
+
unless sudo
|
20
|
+
machine.read_file! params["file_name"]
|
21
|
+
end
|
22
|
+
end
|
@@ -0,0 +1,36 @@
|
|
1
|
+
param! :machine
|
2
|
+
param! "new_name", default_param: true
|
3
|
+
param "new_domain", default: "local"
|
4
|
+
|
5
|
+
run do |machine, new_name, new_domain|
|
6
|
+
full_name = "#{new_name}.#{new_domain}"
|
7
|
+
|
8
|
+
current = machine.hostname
|
9
|
+
if current == full_name
|
10
|
+
$logger.info "hostname already #{current}, skipping"
|
11
|
+
else
|
12
|
+
machine.sudo "hostname #{full_name}"
|
13
|
+
|
14
|
+
# TODO this might be setup-specific, extract?
|
15
|
+
meta = machine.metadata
|
16
|
+
new_entry = "#{full_name} #{new_name}"
|
17
|
+
if meta["type"] == "host"
|
18
|
+
machine.update_hosts_file(
|
19
|
+
ip: machine.external_ip,
|
20
|
+
content: new_entry
|
21
|
+
)
|
22
|
+
elsif meta["type"] == "vm"
|
23
|
+
machine.update_hosts_file(
|
24
|
+
ip: "127.0.1.1",
|
25
|
+
content: new_entry
|
26
|
+
)
|
27
|
+
end
|
28
|
+
|
29
|
+
# update /etc/hostname
|
30
|
+
machine.write_file(
|
31
|
+
"file_name" => "/etc/hostname",
|
32
|
+
"content" => new_name,
|
33
|
+
"sudo" => true
|
34
|
+
)
|
35
|
+
end
|
36
|
+
end
|