Created
October 9, 2015 19:27
-
-
Save raycrawford/8fb00ceabfd92a238008 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
this_time = Time.new | |
ruby_block 'Update sshd_config' do | |
block do | |
begin | |
file = Chef::Util::FileEdit.new('/etc/ssh/sshd_config') | |
rescue StandardError => e | |
puts "==>### ERROR: #{e.message}" | |
end | |
file.search_file_replace_line(/#?GSSAPIAuthentication yes/, "GSSAPIAuthentication no #Updated by Chef #{this_time.inspect}") | |
file.search_file_replace_line(/#?UseDNS yes/, "UseDNS no #Updated by Chef #{this_time.inspect}") | |
if file.unwritten_changes? | |
file.write_file | |
notifies :restart, 'service[sshd]', :immediately | |
end | |
end | |
end | |
service 'sshd' do | |
action :nothing | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Thank you. In some case (some version of Chef?), we need to do this:
notifies :restart, resources(:service => "sshd"), :immediately
instead of
notifies :restart, 'service[sshd]', :immediately