设为首页 收藏本站
查看: 1952|回复: 0

[经验分享] puppet资源package详细介绍(附案例)

[复制链接]
累计签到:1 天
连续签到:1 天
发表于 2014-4-21 09:23:32 | 显示全部楼层 |阅读模式
一、资源介绍
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


运维网声明 1、欢迎大家加入本站运维交流群:群②:261659950 群⑤:202807635 群⑦870801961 群⑧679858003
2、本站所有主题由该帖子作者发表,该帖子作者与运维网享有帖子相关版权
3、所有作品的著作权均归原作者享有,请您和我们一样尊重他人的著作权等合法权益。如果您对作品感到满意,请购买正版
4、禁止制作、复制、发布和传播具有反动、淫秽、色情、暴力、凶杀等内容的信息,一经发现立即删除。若您因此触犯法律,一切后果自负,我们对此不承担任何责任
5、所有资源均系网友上传或者通过网络收集,我们仅提供一个展示、介绍、观摩学习的平台,我们不对其内容的准确性、可靠性、正当性、安全性、合法性等负责,亦不承担任何法律责任
6、所有作品仅供您个人学习、研究或欣赏,不得用于商业或者其他用途,否则,一切后果均由您自己承担,我们对此不承担任何法律责任
7、如涉及侵犯版权等问题,请您及时通知我们,我们将立即采取措施予以解决
8、联系人Email:admin@iyunv.com 网址:www.yunweiku.com

所有资源均系网友上传或者通过网络收集,我们仅提供一个展示、介绍、观摩学习的平台,我们不对其承担任何法律责任,如涉及侵犯版权等问题,请您及时通知我们,我们将立即处理,联系人Email:kefu@iyunv.com,QQ:1061981298 本贴地址:https://www.yunweiku.com/thread-17991-1-1.html 上篇帖子: 通过MCollective更加安全地实现puppet的推送更新功能 下篇帖子: puppet资源service详细介绍(附案例) package 资源
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

扫码加入运维网微信交流群X

扫码加入运维网微信交流群

扫描二维码加入运维网微信交流群,最新一手资源尽在官方微信交流群!快快加入我们吧...

扫描微信二维码查看详情

客服E-mail:kefu@iyunv.com 客服QQ:1061981298


QQ群⑦:运维网交流群⑦ QQ群⑧:运维网交流群⑧ k8s群:运维网kubernetes交流群


提醒:禁止发布任何违反国家法律、法规的言论与图片等内容;本站内容均来自个人观点与网络等信息,非本站认同之观点.


本站大部分资源是网友从网上搜集分享而来,其版权均归原作者及其网站所有,我们尊重他人的合法权益,如有内容侵犯您的合法权益,请及时与我们联系进行核实删除!



合作伙伴: 青云cloud

快速回复 返回顶部 返回列表