aboutsummaryrefslogtreecommitdiff
path: root/manifests/init.pp
blob: a7ea3102c83cca3768651cb15f66fcc542bf78db (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
# modules/ssh/manifests/init.pp - manage ssh stuff
# Copyright (C) 2007 admin@immerda.ch
#

#modules_dir { "sshd": }

class sshd {
    case $operatingsystem {
        gentoo: { include sshd::gentoo }
        redhat: { include sshd::redhat }
        centos: { include sshd::centos }
        openbsd: { include sshd::openbsd }
        debian: { include sshd::debian }
        ubuntu: { include sshd::ubuntu }
        default: { include sshd::default }
    }
}


class sshd::base {
	$real_sshd_config_source = $sshd_config_source ? {
	    '' => "sshd/sshd_config/${operatingsystem}_normal.erb",
    	default => $source,
	}

    $real_sshd_allowed_users = $sshd_allowed_users ? {
        ''  => 'root',
    	default => $sshd_allowed_users,
    }

    file { 'sshd_config':
        path => '/etc/ssh/sshd_config',
        owner => root,
        group => 0,
        mode => 600,
        content => template("${real_sshd_config_source}"),
    }
}

class sshd::linux inherits sshd::base {
    package{openssh:
	    ensure => present,
	}
    include sshd::service
    File[sshd_config]{
        notify => Service[sshd],
    }
}

class sshd::gentoo inherits sshd::linux {
    Package[openssh]{
        category => 'net-misc',
    }
}

class sshd::debian inherits sshd::linux {
    Package[openssh]{
        name => 'openssh-server',
    }
}
class sshd::ubuntu inherits sshd::debian {}

class sshd::redhat inherits sshd::linux {
    Package[openssh]{
        name => 'openssh-server',
    }
}
class sshd::centos inherits sshd::redhat {}

class sshd::openbsd inherits sshd::base {
    exec{sshd_refresh:
        command => "/bin/kill -HUP `/bin/cat /var/run/sshd.pid`",
	    refreshonly => true,
    }
    File[sshd_config]{
        notify => Exec[sshd_refresh],
    }
}

### service stuff 
class sshd::service {
    case $operatingsystem {
        debian: { include sshd::service::debian }
        ubuntu: { include sshd::service::ubuntu }
        default: { include sshd::service::base }
    }
}

class sshd::service::base {
    service{'sshd':
        name => 'sshd',
        enable => true,
        ensure => running,
		require => Package[openssh],
     }
}

class sshd::service::debian inherits sshd::service::base {
    Service[sshd]{
        name => 'ssh',
    }
}
class sshd::service::ubuntu inherits sshd::service::debian {}

### defines 
define sshd::deploy_auth_key(
        $source = '', 
        $user = 'root', 
        $target_dir = '/root/.ssh/', 
        $group = '' ) {

        $real_target = $target_dir ? {
                '' => "/home/$user/.ssh/",
                default => $target_dir,
        }

        $real_group = $group ? {
                '' => 0,
                default => $group,
        }

        $real_source = $source ? {
            '' => [ "puppet://$server/files/sshd/authorized_keys/${name}",
                    "puppet://$server/sshd/authorized_keys/${name}" ],
            default => "puppet://$server/$source",
        }

        file {$real_target:
                ensure => directory,
                owner => $user,
                group => $real_group,
                mode => 700,
        }

        file {"authorized_keys_${user}":
                path => "$real_target/authorized_keys",
                owner => $user,
                group => $real_group,
                mode => 600,
                source => $real_source,
        }
}