通过 Puppet 删除目录的非托管文件

Delete unmanaged files of a directory via Puppet

我制作了一个小模块,能够在 hiera 中为 php-fpm 创建池并将它们保存在 /etc/php5/fpm.d/ 中的节点上。 每个节点(因此 pool.conf 文件)都是由 Puppet 中的资源生成的。

我的hiera长这样

phpfpm::pools:
  poolname:
    listen: '127.0.0.1:9000'
    some:   'other'
  anotherpoolname:
    listen: '127.0.0.1:9001'
    other:  'value'

现在,我遇到了一个问题,我不知道如何自动删除所有不是由 puppet 创建的文件。例如。如果用户在 /etc/php5/fpm.d/ 中手动创建了一个新的 conf 文件,它应该被 puppet 删除。

我已经尝试在模块中清除,但它删除了除将在当前资源中创建的文件之外的所有文件。

有什么建议吗?

我不确定我理解你的代码是如何工作的,但我认为你需要做一些类似于我在这里做的事情来清除 yum.repos.d 目录:

希拉:

profile::base::yum::repos:
  'C7.0.1406-base':
    ensure: 'present'
    baseurl: 'http://vault.centos.org/7.0.1406/os/$basearch/'
    descr: 'CentOS-7.0.1406 - Base'
    enabled: '0'
    gpgcheck: '1'
    gpgkey: 'file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-7'
  'C7.0.1406-centosplus':
    ensure: 'present'
    baseurl: 'http://vault.centos.org/7.0.1406/centosplus/$basearch/'
    descr: 'CentOS-7.0.1406 - CentOSPlus'
    enabled: '0'
    gpgcheck: '1'
    gpgkey: 'file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-7'

清单:

class profile::base::yum (
  Hash [String, Hash[String, String]] $repos,
) {
  Yumrepo {
    stage => 'pre',
  }
  create_resources(yumrepo, $repos)

  # Since we must purge the file resources in
  # /etc/yum.repos.d/, we must also declare the 
  # associated files to prevent them also
  # being purged.

  keys($repos).each |String $yumrepo| {
    file { "/etc/yum.repos.d/${yumrepo}.repo": }
    ->
    Yumrepo[$yumrepo]
  }
  file { '/etc/yum.repos.d/':
    ensure  => directory,
    recurse => true,
    purge   => true,
  }
}