1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
|
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
|
class
motd::exec {
include
motd::exec1
}
class
motd::exec1 {
exec { [
"chkconfig iptables off"
,
"chkconfig ip6tables off"
,]:
path => [
"/usr/bin"
,
"/usr/sbin"
,
"/bin"
,
"/sbin"
],
logoutput => on_failure,
}
}
|
1
2
3
4
5
6
7
8
9
10
11
|
[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
'1378284783'
notice: /Stage[main]/Motd::Exec1/Exec[chkconfig iptables off]/returns: executed successfully
notice: /Stage[main]/Motd::Exec1/Exec[chkconfig ip6tables off]/returns: executed successfully
notice: Finished catalog run
in
0.17
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
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
|
class
source {
include
source::file1,source::exec1,source::exec2,source::exec3,source::user
notify {
"nstallation nginx package through the source code nginx-0.8.42.tar.gz"
:
withpath =>
true
,
}
}
class
source::user{
group {
"nginx"
: #建立组nginx
ensure => present,
gid =>
1000
}
user {
"nginx"
: #建立用户nginx
ensure => present,
uid =>
1000
,
gid =>
1000
,
groups => [
"nginx"
],
# membership => minimum,
shell =>
"/sbin/nologin"
,
require => Group[
"nginx"
]
}
}
class
source::file1{ #远程下载nginx源码包
file{
"nginx"
:
name =>
"/tmp/rhel5/nginx/nginx-0.8.42.tar.gz"
,
owner =>
"root"
,
group =>
"root"
,
mode =>
0700
,
source =>
"puppet://$puppetserver/modules/source/nginx-0.8.42.tar.gz"
,
backup =>
'main'
,
require => Class[
"source::exec1"
],
}
}
class
source::exec1{
exec {
"create nginx_pag"
:
command =>
"mkdir /tmp/rhel5/nginx "
,
path => [
"/usr/bin"
,
"/usr/sbin"
,
"/bin"
,
"/sbin"
],
creates =>
"/tmp/rhel5/nginx"
, #目录或文件不存在的情况下执行command
}
}
class
source::exec2{
exec {
"install nginx"
:
cwd =>
"/tmp/rhel5/nginx"
, #目录存在的情况下执行command
command =>
"tar -zxvf nginx-0.8.42.tar.gz && cd nginx-0.8.42 &&./configure --user=nginx --group=nginx --prefix=/usr/local/nginx --without-http-cache && make&&make install"
,
path => [
"/usr/bin"
,
"/usr/sbin"
,
"/bin"
,
"/sbin"
],
logoutput => on_failure,
unless =>
"/bin/ls /usr/local/nginx/conf"
, #命令返回值不为
0
的情况下执行commond
require => Class[source::file1,source::user]
notify => Class[
"source::exec3"
],
}
}
class
source::exec3{
exec {
"updatedb"
:
command =>
"updatedb"
,
path => [
"/usr/bin"
,
"/usr/sbin"
,
"/bin"
,
"/sbin"
],
refreshonly =>
true
, #触发更新的时候执行command
subscribe => Class[
"source::exec2"
],
}
}
[root@puppetserver manifests]#
|
1
2
3
4
5
|
[root@agent3 rhel5]# cat /etc/passwd | grep nginx
[root@agent3 rhel5]# cat /etc/group | grep nginx
[root@agent3 rhel5]# ll /tmp/rhel5/
total
0
[root@agent3 rhel5]# ll /usr/local/ | grep nginx
|
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
'1378366520'
notice: /Stage[main]/Source::Exec1/Exec[create nginx_pag]/returns: executed successfully
notice: /Stage[main]/Source/Notify[nstallation nginx
package
through the source code nginx-
0.8
.
42
.tar.gz]/message: nstallation nginx
package
through the source code nginx-
0.8
.
42
.tar.gz
notice: /Stage[main]/Source/Notify[nstallation nginx
package
through the source code nginx-
0.8
.
42
.tar.gz]/message: defined
'message'
as
'nstallation nginx package through the source code nginx-0.8.42.tar.gz'
notice: /Stage[main]/Source::File1/File[nginx]/ensure: defined content
as
'{md5}2818e8b03512b239f1238d702703bcf3'
notice: /Stage[main]/Source::User/Group[nginx]/ensure: created
notice: /Stage[main]/Source::User/User[nginx]/ensure: created
notice: /Stage[main]/Source::Exec2/Exec[install nginx]/returns: executed successfully
info: /Stage[main]/Source::Exec2/Exec[install nginx]: Scheduling refresh of Class[Source::Exec3]
info: Class[Source::Exec2]: Scheduling refresh of Exec[updatedb]
info: Class[Source::Exec3]: Scheduling refresh of Exec[updatedb]
notice: /Stage[main]/Source::Exec3/Exec[updatedb]: Triggered
'refresh'
from
2
events
notice: Finished catalog run
in
18.83
seconds
|
1
|
|
1
2
3
4
5
6
7
8
9
10
11
12
13
14
|
[root@agent3 rhel5]# cat /etc/passwd | grep nginx
nginx:x:
1000
:
1000
::/home/nginx:/sbin/nologin
[root@agent3 rhel5]# cat /etc/group | grep nginx
nginx:x:
1000
:nginx
[root@agent3 rhel5]# ll /tmp/rhel5/nginx/
total
632
drwxr-xr-x.
8
nginx nginx
4096
Sep
5
14
:
29
nginx-
0.8
.
42
-rwx------.
1
root root
642593
Sep
5
14
:
29
nginx-
0.8
.
42
.tar.gz
[root@agent3 rhel5]# ll /usr/local/nginx/
total
16
drwxr-xr-x.
2
root root
4096
Sep
5
14
:
30
conf
drwxr-xr-x.
2
root root
4096
Sep
5
14
:
30
html
drwxr-xr-x.
2
root root
4096
Sep
5
14
:
30
logs
drwxr-xr-x.
2
root root
4096
Sep
5
14
:
30
sbin
|
1
2
3
4
5
6
7
8
9
10
11
|
[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
'1378366520'
notice: /Stage[main]/Source/Notify[nstallation nginx
package
through the source code nginx-
0.8
.
42
.tar.gz]/message: nstallation nginx
package
through the source code nginx-
0.8
.
42
.tar.gz
notice: /Stage[main]/Source/Notify[nstallation nginx
package
through the source code nginx-
0.8
.
42
.tar.gz]/message: defined
'message'
as
'nstallation nginx package through the source code nginx-0.8.42.tar.gz'
notice: Finished catalog run
in
0.32
seconds
|