教自己的傀儡。
使用Ubuntu 11.10 Puppet 2.7.1(直接从apt)
在单个节点上运行一些testing脚本( http://docs.puppetlabs.com/learning/manifests.html )。
我做了一个清单,安装并启动apache2包…都很好。
现在我想反过来,我做一个清除apache2包的清单。 这个成功完成,问题是puppet只能删除apache2包,并不是所有的apache2包带来的(我认为apache2.2-bin是主要的)…所以apache2服务仍然安装并运行在系统上。
如果我是用apt-get来做这件事的话,我只会做一个“apt-get autoremove”,但是我怎么能让puppet为我做这个?
不幸的是,使用内置的资源types没有好的办法,只有两个不太好的select。
“正确”的方式是为所有你想摆脱的软件包定义一个package资源:
package { 'apache2.2-common': ensure => purged, } package { 'apache2-utils': ensure => purged, } # etc ...
而“不适当的”,但更易于pipe理的方法是设置一个exec资源,以便在删除apache2包时运行依赖包的autoremove:
package { 'apache2': ensure => purged, } exec { 'autoremove': command => '/usr/bin/apt-get autoremove --purge -y', # We don't want this running every time the puppet agent runs, # so we'll set it to only run when the apache2 purge actually happens. # Note that this would not run on your node that already has the # apache2 package removed, since it won't trigger any more changes # to the package. refreshonly => true, subscribe => Package['apache2'], }
有了这两个选项,第二个选项肯定更有吸引力 – 尽可能地坚持内置types是非常好的,但是当你移除一个具有大量依赖项的包时,这是不实际的。
你可以拥有一个只有在apache包被移除时才运行的exec资源。
package { "apache2": ensure => absent, } exec { "remove-apache-dependencies" command => "apt-get -y autoremove", subscribe => Package["apache2"], refreshonly => true, }