class Sprinkle::Installers::ReplaceText
Replace text installer¶ ↑
This installer replaces a text with another one in a file.
Example Usage¶ ↑
Change ssh port in /etc/ssh/sshd_config
package :magic_beans do replace_text 'Port 22', 'Port 2500', '/etc/ssh/sshd_config' end
If you user has access to 'sudo' and theres a file that requires privileges, you can pass :sudo => true
package :magic_beans do replace_text 'Port 22', 'Port 2500', '/etc/ssh/sshd_config', :sudo => true end
A special verify step exists for this very installer its known as file_contains, it will test that a file indeed contains a substring that you send it.
Public Instance Methods
announce()
click to toggle source
# File lib/sprinkle/installers/replace_text.rb, line 42 def announce log "--> Replace '#{@regex}' with '#{@text}' in file #{@path}" end
replace_text(regex, text, path, options={}, &block)
click to toggle source
# File lib/sprinkle/installers/replace_text.rb, line 30 def replace_text(regex, text, path, options={}, &block) install ReplaceText.new(self, regex, text, path, options, &block) end
Protected Instance Methods
escape_sed_arg(s)
click to toggle source
# File lib/sprinkle/installers/replace_text.rb, line 48 def escape_sed_arg(s) escape_shell_arg(s).gsub("/", "\\\\/").gsub('&', '\\\&') end