本文共 4770 字,大约阅读时间需要 15 分钟。
puppet成长日记二 Package资源详细介绍及案例分析
一、系统环境
1、puppet服务端Release:RHEL6.4HOSTNAME: puppetserver.rsyslog.orgTCP/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: agent1.rsyslog.orgTCP/IP: 172.16.200.101/24Packages:puppet-2.7.21-1.el5mcollective-2.2.4-1.el53、puppet节点Release: RHEL6.4HOSTNAME: agent3.rsyslog.orgTCP/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 有关不同操作系统支持类型请查阅Provider | holdable | install options | installable | purgeable | uninstall options | uninstallable | upgradeable | versionable |
---|---|---|---|---|---|---|---|---|
aix | X | X | X | X | ||||
appdmg | X | |||||||
apple | X | |||||||
apt | X | X | X | X | X | X | ||
aptitude | X | X | X | X | X | X | ||
aptrpm | X | X | X | X | X | |||
blastwave | X | X | X | |||||
dpkg | X | X | X | X | X | |||
fink | X | X | X | X | X | X | ||
freebsd | X | X | ||||||
gem | X | X | X | X | ||||
hpux | X | X | ||||||
macports | X | X | X | X | ||||
msi | X | X | X | X | ||||
nim | X | X | X | X | ||||
openbsd | X | X | X | |||||
opkg | X | X | X | |||||
pacman | X | X | X | |||||
pip | X | X | X | X | ||||
pkg | X | X | X | X | X | |||
pkgdmg | X | |||||||
pkgin | X | X | ||||||
pkgutil | X | X | X | |||||
portage | X | X | X | X | ||||
ports | X | X | X | |||||
portupgrade | X | X | X | |||||
rpm | X | X | X | X | ||||
rug | X | X | X | X | ||||
sun | X | X | X | X | ||||
sunfreeware | X | X | X | |||||
up2date | X | X | X | |||||
urpmi | X | X | X | X | ||||
windows | X | X | X | X | ||||
yum | X | X | X | X | X | |||
zypper | X | X | X | X |
三、资源示例
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 agent1.rsyslog.orginfo: Applying configuration version '1378200479'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.el52.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 agent1.rsyslog.orginfo: 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测试
[root@agent1 rhel5]# rpm -qa postfixpostfix-2.3.3-2.3.el5_6[root@agent1 rhel5]# puppet agent --testinfo: Caching catalog for agent1.rsyslog.orginfo: 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 agent1.rsyslog.orginfo: 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.rpm5.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 agent1.rsyslog.orginfo: 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
转载地址:http://gpgyx.baihongyu.com/