|
一、资源介绍
Description
Manage packages. There is a basic dichotomy in package support right now: Some package types (e.g., yum and apt) can retrieve their own package files, while others (e.g., rpm and sun) cannot. For those package formats that cannot retrieve their own files, you can use the source parameter to point to the correct file.
Puppet will automatically guess the packaging format that you are using based on the platform you are on, but you can override it using the provider parameter; each provider defines what it requires in order to function, and you must meet those requirements to use a given provider.
Autorequires: If Puppet is managing the files specified as a package’s adminfile, responsefile, or source, the package resource will autorequire those files.
Attributes
package { 'resource title':
name => # (namevar) The package name. This is the name that the...
ensure => # What state the package should be in. On...
adminfile => # A file containing package defaults for...
allowcdrom => # Tells apt to allow cdrom sources in the...
category => # A read-only parameter set by the...
configfiles => # Whether configfiles should be kept or replaced.
description => # A read-only parameter set by the...
flavor => # OpenBSD supports 'flavors', which are further...
install_options => # An array of additional options to pass when...
instance => # A read-only parameter set by the...
platform => # A read-only parameter set by the...
provider => # The specific backend to use for this `package...
responsefile => # A file containing any necessary answers to...
root => # A read-only parameter set by the...
source => # Where to find the actual package. This must be...
status => # A read-only parameter set by the...
uninstall_options => # An array of additional options to pass when...
vendor => # A read-only parameter set by the...
# ...plus any applicable metaparameters.
}
1、实现功能
1.1 管理那些软件包被安装,那些软件包被卸载
1.2 管理软件包是否更新
1.3 要求系统配置yum源(RedHat系统)、zypper源(Suse系统)等等
1.4 有关不同操作系统支持类型请查阅http://docs.puppetlabs.com/references/stable/type.html
二、系统环境
1、puppet服务端
Release:RHEL6.4
HOSTNAME: puppetserver.kisspuppet.com
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.kisspuppet.com
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.kisspuppet.com
TCP/IP: 172.16.200.103/24
Packages:
puppet-2.7.21-1.el6
mcollective-2.2.4-1.el6
三、支持参数
2.1 ensure => {present|installed|absent|latest|purged|"version"}, 指定文件的目标状态
=> present|installed, 检查文件是否存在,不存在则新建之
=> absent, 无其他软件依赖,可删除,否则会报错。
=> latest, 检查文件是否为最新版本,否则升级为最新版本
=> purged, 删除该包包括所有依赖的包,有风险慎用
=> "2.7.21-1", 指定某一个版本处于安装状态
2.2 name => package name, 包的名字,默认与title相同可不写
2.3 provider => rpm, 要求通过rpm命令安装包,需要通过source指定安装那些包
四、资源示例
1、示例一
1.1 实现功能
*判断系统为RedHat的情况下安装mysql-server和mysql,系统为SLES的情况下安装mysql和mysql-client,其他系统安装mysql-server和mysql包
*要求安装的包一直处于安装状态
1.2 配置说明
class mysql::install{
package { "mysql":
name => $operatingsystem ?
{
RedHat => ["mysql-server","mysql"],
SLES => ["mysql","mysql-client"],
default => ["mysql-server","mysql"],
},
ensure => installed,
}
1.3 客户端agent1测试
[iyunv@agent1 ~]# puppet agent --test
info: Retrieving plugin
info: Loading facts in /var/lib/puppet/lib/facter/my_apply2.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/backup_date.rb
info: Caching catalog for agent1.kisspuppet.com
info: Applying configuration version '1378200479'
notice: /Stage[main]/Mysql::Install/Package[mysql]/ensure: created
notice: /Stage[main]/Mysql::Service/Service[mysqld]/ensure: ensure changed 'stopped' to 'running'
notice: Finished catalog run in 9.68 seconds
2、示例二
2.1 实现功能
*要求安装的autofs包版本为5.0.1-0.rc2.163.el5
2.2 配置说明
class autofs::install{
package { "autofs":
ensure => "5.0.1-0.rc2.163.el5",
}
}
2.3 客户端agent2测试
[iyunv@agent1 ~]# puppet agent --test
info: Caching catalog for agent1.kisspuppet.com
info: Applying configuration version '1378201631'
notice: /Stage[main]/Autofs::Install/Package[autofs]/ensure: created
3、示例三
3.1 实现功能
*要求安装的postfix包版本更新至最新版本
3.2 配置说明
class postfix::install{
package { "postfix":
ensure => latest,
}
}
2.3 客户端agent2测试
[iyunv@agent1 rhel5]# rpm -qa postfix
postfix-2.3.3-2.3.el5_6
[iyunv@agent1 rhel5]# puppet agent --test
info: Caching catalog for agent1.kisspuppet.com
info: Applying configuration version '1378202947'
notice: /Stage[main]/Postfix::Install/Package[postfix]/ensure: ensure changed '2.3.3-2.3.el5_6' to '2:2.5.17-1.rhel5'
notice: Finished catalog run in 6.42 seconds
[iyunv@agent1 rhel5]# rpm -qa postfix
postfix-2.5.17-1.rhel5
[iyunv@agent1 rhel5]#
4、示例四
4.1 实现功能
*要求postfix包不允许被安装
4.2 配置说明
class postfix::install{
package { "postfix":
ensure => absent,
}
}
4.3 客户端agent2测试
[iyunv@agent1 rhel5]# rpm -qa postfix
postfix-2.5.17-1.rhel5
[iyunv@agent1 rhel5]# puppet agent --test
info: Caching catalog for agent1.kisspuppet.com
info: Applying configuration version '1378203359'
notice: /Stage[main]/Postfix::Install/Package[postfix]/ensure: removed
notice: Finished catalog run in 1.00 seconds
[iyunv@agent1 rhel5]# rpm -qa postfix
5、示例五
5.1 实现功能
*要求通过rpm命令安装本地rpm包/tmp/rhel5/postfix-2.5.17-1.rhel5.x86_64.rpm
5.2 配置说明
class postfix::install{
package { "postfix":
ensure => present,
provider => rpm,
source => "/tmp/rhel5/postfix-2.5.17-1.rhel5.x86_64.rpm",
}
}
5.3 客户端agent1测试
[iyunv@agent1 rhel5]# rpm -qa postfix
[iyunv@agent1 rhel5]# puppet agent --test --verbose
info: Caching catalog for agent1.kisspuppet.com
info: Applying configuration version '1378204203'
notice: /Stage[main]/Postfix::Install/Package[postfix]/ensure: created
notice: Finished catalog run in 3.43 seconds
[iyunv@agent1 rhel5]# rpm -qa postfix
postfix-2.5.17-1.rhel5
|
|