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

[经验分享] Puppet package资源介绍(二十四)

[复制链接]

尚未签到

发表于 2017-10-31 16:14:38 | 显示全部楼层 |阅读模式
package资源
package资源可以借助本地包管理系统帮我们安装软件,也可以通过参数指定软件包来安装.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
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软件包.
1
2
3
4
5
[iyunv@sh-web1 ~]# cat httpd.pp
package {"httpd":
    ensure => present,
    provider => 'yum',
}





provider:这个参数默认也是从yum源安装,所以不需要也是可以的,除非你需要特别安装安装包.

运行结果:
1
2
3
4
[iyunv@sh-web1 ~]# 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



检查:
1
2
[iyunv@sh-web1 ~]# rpm -qa httpd
httpd-2.2.15-60.el6.centos.5.x86_64





示例二:
安装haproxy.(通过source源指定软件包,通过rpm方式安装.)

安装haproxy的puppet代码.
1
2
3
4
5
6
[iyunv@sh-web1 ~]# cat haproxy.pp
package {"haproxy":
    ensure => present,
    source => '/tmp/haproxy-1.5.2-2.el6.x86_64.rpm',
    provider => 'rpm',
}





运行puppet代码的结果.
1
2
3
4
5
6
[iyunv@sh-web1 ~]# 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
[iyunv@sh-web1 ~]# rpm -qa haproxy
haproxy-1.5.2-2.el6.x86_64




示例三:
puppet 一次安装多个软件包.
1
2
3
4
5
6
7
[iyunv@sh-web1 ~]# cat many.pp
package {["autoconf",
    "mysql-devel",
    "make",
    "gcc"]:
    ensure => present,
}



运行结果:
1
2
3
4
5
6
7
8
9
10
[iyunv@sh-web1 ~]# 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
[iyunv@sh-web1 ~]# rpm -qa make
make-3.81-23.el6.x86_64
[iyunv@sh-web1 ~]# rpm -qa autoconf
autoconf-2.63-5.1.el6.noarch
[iyunv@sh-web1 ~]# rpm -qa mysql-devel
mysql-devel-5.1.73-8.el6_8.x86_64





前几篇文章中有一个php模块的puppet代码如下:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
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"],
    }
}




1
2
3
4
$packages = ['php','php-devel']
package {[$packages]:
    ensure=> "installed"
}





$packages 等于的并不是数组,是数组中的元素,所以下面的package安装还是需要"[]"的.

官网给出的示例
name

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
# 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'],
}






运维网声明 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-406343-1-1.html 上篇帖子: Puppet group资源介绍(二十三) 下篇帖子: Puppet service资源介绍(二十五)
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

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

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

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

扫描微信二维码查看详情

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


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


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


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



合作伙伴: 青云cloud

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