六,Package资源属性
Package { “package name”:
Ensure =>present/absent/latest/{version}/purged,
#present 只要存在即可
#absent 无依赖可删除,如果有依赖会报错,并不删除,只能删除没有依赖的软件包
#lastest 会升级到最新版本
#version 指定安装具体某个版本
#purged 删除该包包括有依赖性的包,如果有依赖,则依赖包也会被删除,使用有风险,少使用
Name => package name,
#在titile里指定了这里可以省略
}
实例
vim site.pp
node "client" {
file { "/test_client":
ensure => present,
}
package { "httpd":
ensure => present,
}
[root@client ~]# puppet agent --test
Info: Retrieving plugin
Info: Caching catalog for client
Info: Applying configuration version '1375177502'
Notice: /Stage[main]//Node[client]/File[/test_client]/ensure: created
Notice: /Stage[main]//Node[client]/Package[httpd]/ensure: created
Notice: Finished catalog run in 42.28 seconds
vim site.pp
node "client" {
file { "/test_client":
ensure => present,
}
package { "openldap":
ensure => absent,
}
[root@client ~]# puppet agent --test
Info: Retrieving plugin
Info: Caching catalog for client
Info: Applying configuration version '1375177769'
Error: Execution of '/bin/rpm -e openldap-2.4.23-26.el6.x86_64' returned 1: error: Failed dependencies:
liblber-2.4.so.2()(64bit) is needed by (installed) cyrus-sasl-2.1.23-13.el6.x86_64
liblber-2.4.so.2()(64bit) is needed by (installed) postfix-2:2.6.6-2.2.el6_1.x86_64
liblber-2.4.so.2()(64bit) is needed by (installed) sudo-1.7.4p5-11.el6.x86_64
liblber-2.4.so.2()(64bit) is needed by (installed) apr-util-ldap-1.3.9-3.el6_0.1.x86_64
七,Service资源
Service {“package name”:
Ensure =>running(true)/stopped(false),
Enable =>true/false,
#enable确保资源开机启动还是不启动
Status,start,stop,restart=>command,
#如果不支持标准的命令时,如service xxx start,表示标准的,一些编译的软件,不支付标准的,而要查询资源的属性时,需要执行命令,command表示命令行
Hasrestart => true/false,
#true表示直接执行restart命令重启服务,false表示先对服务stop,再start
Hasstatus =>true/false,
#表示在进程查看服务的状态
}
实例
Vim site.pp
node "client" {
file { "/test_client":
ensure => present,
}
package { "openldap":
ensure => present,
}
service { "httpd":
ensure => running,
}
}
#node 是一个关键字,指定哪台客户端client是客户端主机名,在{}写上需要在client执行的作业
#由于httpd支持标准启动,所以可以不需要定义start =>command
[root@client ~]# puppet agent --test
Info: Retrieving plugin
Info: Caching catalog for client
Info: Applying configuration version '1375179204'
Notice: /Stage[main]//Node[client]/Service[httpd]/ensure: ensure changed 'stopped' to 'running'
Info: /Stage[main]//Node[client]/Service[httpd]: Unscheduling refresh on Service[httpd]
Notice: Finished catalog run in 0.42 seconds
将httpd移到到/root目录下,此时不再支持service来启动,需要指定路径/root/httpd start,那么此时就需要定义start =>command
[root@client ~]# service httpd stop
Stopping httpd: [ OK ]
[root@client ~]# mv /etc/init.d/httpd .
Vim site.pp
node "client" {
file { "/test_client":
ensure => present,
}
package { "openldap":
ensure => present,
}
service { "httpd":
ensure => running,
Start => “/root/httpd start”,
}
}
[root@client ~]# puppet agent --test
Info: Retrieving plugin
Info: Caching catalog for client
Info: Applying configuration version '1375179610'
Notice: /Stage[main]//Node[client]/Service[httpd]/ensure: ensure changed 'stopped' to 'running'
Info: /Stage[main]//Node[client]/Service[httpd]: Unscheduling refresh on Service[httpd]
Notice: Finished catalog run in 0.32 seconds
Vim site.pp
node "client" {
file { "/test_client":
ensure => present,
}
package { "openldap":
ensure => present,
}
service { "httpd":
ensure => running,
#start => “/root/httpd start”,
restart => “/root/httpd restart”,
hasrestart =>”true”,
#hasrestart 要服务支持标准的启动,如果不能则需要将上面的start改成restart
}
}
