puppet成长日记二 Package资源详细介绍及案例分析
一、系统环境
1、puppet服务端Release:RHEL6.4HOSTNAME: TCP/IP: 172.16.200.100/24Packages: puppet-server-2.7.21-1.el6.noarchmcollective-client-2.2.4activemq-5.5.02、puppet节点Release: RHEL5.8HOSTNAME: TCP/IP: 172.16.200.101/24Packages:puppet-2.7.21-1.el5mcollective-2.2.4-1.el53、puppet节点Release: RHEL6.4HOSTNAME: TCP/IP: 172.16.200.103/24Packages:puppet-2.7.21-1.el6mcollective-2.2.4-1.el6
二、资源介绍
1、实现功能
1.1 管理那些软件包被安装,那些软件包被卸载
1.2 管理软件包是否更新
1.3 要求系统配置yum源(RedHat系统)、zypper源(Suse系统)等等
1.4 有关不同操作系统支持类型请查阅/references/stable/type.html#package
2、支持参数
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测试
[root@agent1 ~]# puppet agent --testinfo: Retrieving plugininfo: Loading facts in /var/lib/puppet/lib/facter/my_apply2.rbinfo: Loading facts in /var/lib/puppet/lib/facter/my_apply1.rbinfo: Loading facts in /var/lib/puppet/lib/facter/my_apply3.rbinfo: Loading facts in /var/lib/puppet/lib/facter/backup_date.rbinfo: Caching catalog for info: Applying configuration version '137879'notice: /Stage[main]/Mysql::Install/Package[mysql]/ensure: creatednotice: /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测试
[root@agent1 ~]# puppet agent --testinfo: Caching catalog for info: Applying configuration version '137831'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测试
[root@agent1 rhel5]# rpm -qa postfixpostfix-2.3.3-2.3.el5_6[root@agent1 rhel5]# puppet agent --testinfo: Caching catalog for 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[root@agent1 rhel5]# rpm -qa postfixpostfix-2.5.17-1.rhel5[root@agent1 rhel5]#
4、示例四 4.1 实现功能
*要求postfix包不允许被安装
4.2 配置说明
class postfix::install{package { "postfix":ensure => absent,}}
4.3 客户端agent2测试
[root@agent1 rhel5]# rpm -qa postfixpostfix-2.5.17-1.rhel5[root@agent1 rhel5]# puppet agent --testinfo: Caching catalog for info: Applying configuration version '1378203359'notice: /Stage[main]/Postfix::Install/Package[postfix]/ensure: removednotice: Finished catalog run in 1.00 seconds[root@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测试
[root@agent1 rhel5]# rpm -qa postfix[root@agent1 rhel5]# puppet agent --test --verboseinfo: Caching catalog for info: Applying configuration version '1378204203'notice: /Stage[main]/Postfix::Install/Package[postfix]/ensure: creatednotice: Finished catalog run in 3.43 seconds[root@agent1 rhel5]# rpm -qa postfixpostfix-2.5.17-1.rhel5
欢迎puppet精英加入自动化运维管理群 296934942
如果觉得《puppet成长日记二 Package资源详细介绍及案例分析》对你有帮助,请点赞、收藏,并留下你的观点哦!