]> git.openstreetmap.org Git - chef.git/blob - cookbooks/openssh/recipes/default.rb
Use packaged pbzip2
[chef.git] / cookbooks / openssh / recipes / default.rb
1 #
2 # Cookbook Name:: openssh
3 # Recipe:: default
4 #
5 # Copyright 2010, OpenStreetMap Foundation.
6 # Copyright 2008-2009, Opscode, Inc.
7 #
8 # Licensed under the Apache License, Version 2.0 (the "License");
9 # you may not use this file except in compliance with the License.
10 # You may obtain a copy of the License at
11 #
12 #     http://www.apache.org/licenses/LICENSE-2.0
13 #
14 # Unless required by applicable law or agreed to in writing, software
15 # distributed under the License is distributed on an "AS IS" BASIS,
16 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17 # See the License for the specific language governing permissions and
18 # limitations under the License.
19 #
20
21 include_recipe "networking"
22
23 package "openssh-client"
24 package "openssh-server"
25
26 service "ssh" do
27   action [ :enable, :start ]
28   if node[:lsb][:release].to_f >= 10.04
29     supports :status => true, :restart => true, :reload => true
30   else 
31     supports :restart => true, :reload => true
32   end
33 end
34
35 hosts = search(:node, "networking:interfaces").sort_by do |node|
36   node[:hostname]
37 end.collect do |node|
38   names = [ node[:hostname] ]
39
40   node.interfaces(:role => :external).each do |interface|
41     names |= [ "#{node[:hostname]}.openstreetmap.org" ]
42     names |= [ "#{node[:hostname]}.#{interface[:zone]}.openstreetmap.org" ]
43   end
44
45   unless node.interfaces(:role => :internal).empty?
46     names |= [ "#{node[:hostname]}.#{node[:networking][:roles][:external][:zone]}.openstreetmap.org" ]
47   end
48
49   Hash[
50     :names => names.sort,
51     :addresses => node.ipaddresses.sort,
52     :rsa => node[:keys][:ssh][:host_rsa_public],
53     :dsa => node[:keys][:ssh][:host_dsa_public]
54   ]
55 end
56
57 template "/etc/ssh/ssh_config" do
58   source "ssh_config.erb"
59   mode 0644
60   owner "root"
61   group "root"
62 end
63
64 template "/etc/ssh/ssh_known_hosts" do
65   source "ssh_known_hosts.erb"
66   mode 0444
67   owner "root"
68   group "root"
69   backup false
70   variables(
71     :hosts => hosts
72   )
73 end
74
75 firewall_rule "accept-ssh" do
76   action :accept
77   source "net"
78   dest "fw"
79   proto "tcp:syn"
80   dest_ports "ssh"
81 end