1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
|
1
、puppet服务端
Release:RHEL6.
4
HOSTNAME: puppetserver.rsyslog.org
TCP/IP:
172.16
.
200.100
/
24
Packages:
puppet-server-
2.7
.
21
-
1
.el6.noarch
mcollective-client-
2.2
.
4
activemq-
5.5
.
0
2
、puppet节点
Release: RHEL5.
8
HOSTNAME: agent1.rsyslog.org
TCP/IP:
172.16
.
200.101
/
24
Packages:
puppet-
2.7
.
21
-
1
.el5
mcollective-
2.2
.
4
-
1
.el5
3
、puppet节点
Release: RHEL6.
4
HOSTNAME: agent3.rsyslog.org
TCP/IP:
172.16
.
200.103
/
24
Packages:
puppet-
2.7
.
21
-
1
.el6
mcollective-
2.2
.
4
-
1
.el6
|
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
|
class
ssh::service{
service { $ssh::params::ssh_service_name:
ensure => running,
hasstatus =>
false
,
hasrestart =>
true
,
enable =>
true
,
subscribe => Class[
"ssh::config"
],
}
}
或
class
ssh::service{
service { $ssh::params::ssh_service_name:
ensure => stopped,
hasstatus =>
false
,
hasrestart =>
true
,
enable =>
true
,
subscribe => Class[
"ssh::config"
],
}
}
|
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
|
[root@agent3 ~]# puppet agent --test
info: Retrieving plugin
info: Loading facts
in
/
var
/lib/puppet/lib/facter/backup_date.rb
info: Loading facts
in
/
var
/lib/puppet/lib/facter/my_apply1.rb
info: Loading facts
in
/
var
/lib/puppet/lib/facter/my_apply3.rb
info: Loading facts
in
/
var
/lib/puppet/lib/facter/my_apply2.rb
info: Caching catalog
for
agent3.rsyslog.org
info: Applying configuration version
'1378281102'
notice: Finished catalog run
in
0.38
seconds
[root@agent3 ~]#
[root@agent3 ~]# puppet agent --test
info: Retrieving plugin
info: Loading facts
in
/
var
/lib/puppet/lib/facter/backup_date.rb
info: Loading facts
in
/
var
/lib/puppet/lib/facter/my_apply1.rb
info: Loading facts
in
/
var
/lib/puppet/lib/facter/my_apply3.rb
info: Loading facts
in
/
var
/lib/puppet/lib/facter/my_apply2.rb
info: Caching catalog
for
agent3.rsyslog.org
info: Applying configuration version
'1378280861'
notice: /Stage[main]/Ssh::Service/Service[sshd]/ensure: ensure changed
'running'
to
'stopped'
notice: Finished catalog run
in
0.54
seconds
|
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
|
class
ssh::service{
service { $ssh::params::ssh_service_name:
ensure => running,
hasstatus =>
true
,
hasrestart =>
true
,
enable =>
true
,
subscribe => Class[
"ssh::config"
],
# provider => base|daemontools|init,
provider => init,
path =>
"/etc/rc.d/init.d"
,
restart =>
"/etc/rc.d/init.d/sshd reload"
,
start =>
"/etc/rc.d/init.d/sshd start"
,
stop =>
"/etc/rc.d/init.d/sshd stop"
,
}
}
class
ssh::config{
file { $ssh::params::ssh_service_config:
ensure => present,
owner =>
'root'
,
group =>
'root'
,
mode =>
0640
,
source =>
"puppet:///modules/ssh/etc/ssh/sshd_config"
,
# backup =>
".$backup_date.bak"
,
backup =>
'main'
,
require => Class[
"ssh::install"
],
notify => Class[
"ssh::service"
], #等同于
class
ssh::service中的subscribe
}
}
|
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
|
case
"$1"
in
start)
start
;;
stop)
stop
;;
restart)
stop
start
echo
"sshd restart stop-start"
>>/tmp/sshd_status
;;
reload)
reload
echo
"sshd reload"
>>/tmp/sshd_status
;;
|
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
|
[root@agent3 ~]# puppet agent --test
info: Retrieving plugin
info: Loading facts
in
/
var
/lib/puppet/lib/facter/backup_date.rb
info: Loading facts
in
/
var
/lib/puppet/lib/facter/my_apply1.rb
info: Loading facts
in
/
var
/lib/puppet/lib/facter/my_apply3.rb
info: Loading facts
in
/
var
/lib/puppet/lib/facter/my_apply2.rb
info: Caching catalog
for
agent3.rsyslog.org
info: Applying configuration version
'1378279503'
notice: /File[/etc/ssh/sshd_config]/content:
--- /etc/ssh/sshd_config
2013
-
09
-
04
15
:
27
:
22.177863699
+
0800
+++ /tmp/puppet-file20130904-
19622
-yy8g9o-
0
2013
-
09
-
04
15
:
29
:
47.791863671
+
0800
@@ -
5
,
8
+
5
,
6
@@
Protocol
2
#AddressFamily any
-# HostKey
for
protocol version
1
-
# Lifetime and size of ephemeral version
1
server key
#KeyRegenerationInterval 1h
#ServerKeyBits
768
info: FileBucket adding {md5}43f5b3f207a1b6fb35e3bd779b83c3f8
info: /File[/etc/ssh/sshd_config]: Filebucketed /etc/ssh/sshd_config to main
with
sum 43f5b3f207a1b6fb35e3bd779b83c3f8
notice: /File[/etc/ssh/sshd_config]/content: content changed
'{md5}43f5b3f207a1b6fb35e3bd779b83c3f8'
to
'{md5}df197ccd4957217616b62a82b890ed98'
info: /File[/etc/ssh/sshd_config]: Scheduling refresh of Class[Ssh::Service]
info: Class[Ssh::Config]: Scheduling refresh of Service[sshd]
info: Class[Ssh::Service]: Scheduling refresh of Service[sshd]
notice: /Service[sshd]: Triggered
'refresh'
from
2
events
notice: Finished catalog run
in
0.97
seconds
[root@agent3 ~]# cat /tmp/sshd_status
sshd reload #可以看到服务是reload而不是restart
[root@agent3 ~]#
|