Skip to content

Instantly share code, notes, and snippets.

@raycrawford
Created October 9, 2015 19:27
Show Gist options
  • Save raycrawford/8fb00ceabfd92a238008 to your computer and use it in GitHub Desktop.
Save raycrawford/8fb00ceabfd92a238008 to your computer and use it in GitHub Desktop.
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
@tuannh99
Copy link

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment