diff --git a/attributes/default.rb b/attributes/default.rb index bd72c86..cf30797 100644 --- a/attributes/default.rb +++ b/attributes/default.rb @@ -1,3 +1,9 @@ +# Defines ssh service name based on distro +default[:ssh][:service_name] = case node["platform_family"] + when "debian","ubuntu" then "ssh" + else "sshd" +end +# # Port on which openssh listens on default[:ssh][:port] = "22" # @@ -56,4 +62,4 @@ # shouldn't really enable root login, but if you really must, DO NOT enable # password authentication. With both options enabled, your server will become # very vulnerable. -default[:ssh][:root_authorized_keys] = [] +default[:ssh][:root_authorized_keys] = [] \ No newline at end of file diff --git a/metadata.rb b/metadata.rb index 75051b2..c21b63e 100644 --- a/metadata.rb +++ b/metadata.rb @@ -2,4 +2,5 @@ maintainer_email "gerhard@lazu.co.uk" license "Apache 2.0" description "Configures openssh, adds system users" -version "1.4.0" +version "1.4.1" +name "ssh-cookbook" \ No newline at end of file diff --git a/providers/config.rb b/providers/config.rb index 255f0ec..410f1a3 100644 --- a/providers/config.rb +++ b/providers/config.rb @@ -2,14 +2,11 @@ bash "Adding #{new_resource.name} to sshd_config" do code %{ set -x - if [[ $(cat /etc/ssh/sshd_config) =~ "#{new_resource.match}" ]]; then - sed -i "s/#*#{new_resource.match}.*/#{new_resource.string}/g" /etc/ssh/sshd_config - else - echo -en "#{new_resource.string}\n" >> /etc/ssh/sshd_config - fi + sed -i '/#*#{new_resource.match}.*/ d' /etc/ssh/sshd_config + echo -en "#{new_resource.string}\n" >> /etc/ssh/sshd_config } not_if %{ egrep -c "^#{new_resource.string}$" /etc/ssh/sshd_config -q } - notifies :restart, resources(:service => "ssh"), :delayed + notifies :restart, resources(:service => node[:ssh][:service_name]), :delayed end end @@ -20,7 +17,7 @@ echo -en "#{new_resource.string}\n" >> /etc/ssh/sshd_config } not_if %{ [[ ! $(cat /etc/ssh/sshd_config) =~ "#{new_resource.match}" ]] } - notifies :restart, resources(:service => "ssh"), :delayed + notifies :restart, resources(:service => node[:ssh][:service_name]), :delayed end end @@ -31,6 +28,6 @@ sed -i '/#{new_resource.match}.*/ d' /etc/ssh/sshd_config } only_if %{ egrep -c "^#{new_resource.string}$" /etc/ssh/sshd_config -q } - notifies :restart, resources(:service => "ssh"), :delayed + notifies :restart, resources(:service => node[:ssh][:service_name]), :delayed end -end +end \ No newline at end of file diff --git a/recipes/chroot.rb b/recipes/chroot.rb index 7e48008..615be07 100644 --- a/recipes/chroot.rb +++ b/recipes/chroot.rb @@ -1,4 +1,6 @@ -service "ssh" +service node[:ssh][:service_name] do + provider Chef::Provider::Service::Upstart if 'ubuntu' == node['platform'] && Chef::VersionConstraint.new('>= 12.04').include?(node['platform_version']) +end ssh_config "Subsystem sftp" do string "Subsystem sftp internal-sftp" diff --git a/recipes/default.rb b/recipes/default.rb index fd6acdf..a35727f 100644 --- a/recipes/default.rb +++ b/recipes/default.rb @@ -1,4 +1,6 @@ -service "ssh" +service node[:ssh][:service_name] do + provider Chef::Provider::Service::Upstart if 'ubuntu' == node['platform'] && Chef::VersionConstraint.new('>= 12.04').include?(node['platform_version']) +end ssh_config "Port" do string "Port #{node[:ssh][:port]}" @@ -51,4 +53,4 @@ ssh_authorized_keys "root" do home "/root" ssh_keys node[:ssh][:root_authorized_keys] -end +end \ No newline at end of file