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

通过Puppet删除目录的非托管文件,puppet,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: '

我制作了一个小模块,可以在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,
  }
}

这正是我要建议的——即,使用
recurse
purge
两种
true
通过
文件
资源管理包含的目录。根据,
purge
将导致删除非托管文件,并且仅删除非托管文件。特别是,通过单独的
File
资源管理的文件不会被清除。我认为代码中的
yumrepo
暂存和元参数对于回答这个问题来说有点不必要。话虽如此,这应该是绝对有效的,但问题含糊其辞地说,像这样的尝试并没有奏效。这肯定回答了前面提到的问题。如果Puppet的顺序没有被很好地理解,那么代码示例可能会令人困惑。也就是说,有可能有人在档案中发现了这个问题,不管怎么说,yum.repos.d问题都会出现在这里,所以我认为保留完整的工作示例是有意义的。