Puppet Ubuntu 删除不再需要的软件包

sMo*_*ely 4 ubuntu puppet ubuntu-11.10

自学木偶。

使用 Ubuntu 11.10 Puppet 2.7.1(直接来自 apt)

在单个节点上运行一些测试脚本(遵循http://docs.puppetlabs.com/learning/manifests.html)。

我做了一个安装和启动 apache2 包的清单......一切都很好。

现在我想扭转这一点,我制作了一个清除 apache2 包的清单。这成功完成,问题是puppet只删除了apache2包,而不是apache2带来的所有包(我认为apache2.2-bin是主要的)......所以apache2服务仍然安装并运行系统上。

如果我用 apt-get 做这件事,我会做一个“apt-get autoremove”,但我怎样才能让 puppet 为我做这件事?

Sha*_*den 7

不幸的是,使用内置资源类型没有好的方法可以做到这一点,只有两个不太好的选择。

“正确”的方法包括package为您要删除的所有包定义资源:

package { 'apache2.2-common':
    ensure => purged,
}
package { 'apache2-utils':
    ensure => purged,
}
# etc ...
Run Code Online (Sandbox Code Playgroud)

而“不正确”但更易于管理的方法是设置一个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'],
}
Run Code Online (Sandbox Code Playgroud)

考虑到这两个选项,第二个选项绝对更有吸引力 - 能够尽可能坚持使用内置类型是很好的,但是当您删除具有大量依赖项的包时,这不切实际。