Puppet package资源介绍(二十四)
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了Puppet package资源介绍(二十四)相关的知识,希望对你有一定的参考价值。
package资源
package资源可以借助本地包管理系统帮我们安装软件,也可以通过参数指定软件包来安装.
package { ‘resource title‘: provider => # (namevar) The specific backend to use for this `package... 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... allow_virtual => # Specifies if virtual package names are allowed... allowcdrom => # Tells apt to allow cdrom sources in the... category => # A read-only parameter set by the... configfiles => # Whether to keep or replace modified config files 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... package_settings => # Settings that can change the contents or... platform => # A read-only parameter set by the... reinstall_on_refresh => # Whether this resource should respond to refresh... responsefile => # A file containing any necessary answers to... root => # A read-only parameter set by the... source => # Where to find the package file. This is only... 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. }
provider:包管理系统,不同的操作平台有着不同的包管理器,如redhat的yum,ubuntu的dpkg等.
name:软件包的名字.
ensure :软件包的状态,installed或present表示安装,absent表示卸载;pureged表示一处软件包;latest表示安装最新的。
adminfile:软件包的默认配置文件.
allowcdrom:通知apt允许使用cdrom作为软件源,可以设置false或者true.
allow_virtual:虚拟包名.
source:软件包的源.
install_options:安装软件包的参数.
参数很多,有安装的也有卸载的卸载参数uninstall_options,不一个一个写了.
示例一:
系统源安装httpd软件包.
[[email protected] ~]# cat httpd.pp package {"httpd": ensure => present, provider => ‘yum‘, }
provider:这个参数默认也是从yum源安装,所以不需要也是可以的,除非你需要特别安装安装包.
运行结果:
[[email protected] ~]# puppet apply httpd.pp Notice: Compiled catalog for sh-web1.localdomain in environment production in 0.04 seconds Notice: /Stage[main]/Main/Package[httpd]/ensure: created Notice: Finished catalog run in 5.69 seconds
检查:
[[email protected] ~]# rpm -qa httpd httpd-2.2.15-60.el6.centos.5.x86_64
示例二:
安装haproxy.(通过source源指定软件包,通过rpm方式安装.)
安装haproxy的puppet代码.
[[email protected] ~]# cat haproxy.pp package {"haproxy": ensure => present, source => ‘/tmp/haproxy-1.5.2-2.el6.x86_64.rpm‘, provider => ‘rpm‘, }
运行puppet代码的结果.
[[email protected] ~]# puppet apply haproxy.pp Notice: Compiled catalog for sh-web1.localdomain in environment production in 0.04 seconds Notice: /Stage[main]/Main/Package[haproxy]/ensure: created Notice: Finished catalog run in 0.61 seconds [[email protected] ~]# rpm -qa haproxy haproxy-1.5.2-2.el6.x86_64
示例三:
puppet 一次安装多个软件包.
[[email protected] ~]# cat many.pp package {["autoconf", "mysql-devel", "make", "gcc"]: ensure => present, }
运行结果:
[[email protected] ~]# puppet apply many.pp Notice: Compiled catalog for sh-web1.localdomain in environment production in 0.04 seconds Notice: /Stage[main]/Main/Package[mysql-devel]/ensure: created Notice: Finished catalog run in 14.96 seconds [[email protected] ~]# rpm -qa make make-3.81-23.el6.x86_64 [[email protected] ~]# rpm -qa autoconf autoconf-2.63-5.1.el6.noarch [[email protected] ~]# rpm -qa mysql-devel mysql-devel-5.1.73-8.el6_8.x86_64
前几篇文章中有一个php模块的puppet代码如下:
class php { include php::phpfpmconf $packages = [‘php‘,‘php-devel‘] package {[$packages]: ensure=> "installed" } package {"php-fpm": ensure => present, } service {"php-fpm": ensure=> running, enable=> true, hasrestart=> true, hasstatus=> true, provider => init, require=> Package["php-fpm"], } }
$packages = [‘php‘,‘php-devel‘] package {[$packages]: ensure=> "installed" }
$packages 等于的并不是数组,是数组中的元素,所以下面的package安装还是需要"[]"的.
官网给出的示例
name
# In the ‘openssl‘ class $ssl = $operatingsystem ? { solaris => SMCossl, default => openssl } package { ‘openssl‘: ensure => installed, name => $ssl, } . etc. . $ssh = $operatingsystem ? { solaris => SMCossh, default => openssh } package { ‘openssh‘: ensure => installed, name => $ssh, require => Package[‘openssl‘], }
本文出自 “青衫解衣” 博客,请务必保留此出处http://215687833.blog.51cto.com/6724358/1973370
以上是关于Puppet package资源介绍(二十四)的主要内容,如果未能解决你的问题,请参考以下文章