【问题标题】:puppet overriding file resource on a module木偶覆盖模块上的文件资源
【发布时间】:2015-07-13 00:30:31
【问题描述】:

我正在使用这个 CIS 模块arildjensen/cis-puppet

并且想要覆盖 CIS 模块上的 /etc/profile 文件声明

所以我创建了这个新清单,遵循这个post

class profile::hadoop::settings inherits cis {

      file { '/etc/profile':
        ensure => 'file',
        owner  => 'root',
        group  => 'root',
        mode   => '0600',
        source => 'puppet:///modules/profile/hadoop/etc/profile',
      }
  }

但是这仍然给出错误

Error: Duplicate declaration: File[/etc/profile] is already declared in file /tmp/vagrant-puppet/modules-ab9b45e51a68912cdc576c81d46a2260/profile/manifests/hadoop/settings.pp:9; cannot redeclare at /tmp/vagrant-puppet/modules-ab9b45e51a68912cdc576c81d46a2260/cis/manifests/linuxcontrols/c0076.pp:12 on node server.localdomain

【问题讨论】:

    标签: linux automation centos puppet


    【解决方案1】:

    资源覆盖的语法与资源声明的语法不同。你正在寻找这个:

    class profile::hadoop::settings inherits cis {
    
        File['/etc/profile'] {
            ensure => 'file',
            owner  => 'root',
            group  => 'root',
            mode   => '0600',
            source => 'puppet:///modules/profile/hadoop/etc/profile',
        }
    }
    

    从语法上讲,它是一个资源引用(这是有道理的),带有附加的属性覆盖列表。

    当然,这是老派的做法。至少从 Puppet 3.0 开始,您还可以使用收集器执行覆盖,在这种情况下您不需要类继承:

    class profile::hadoop::settings {
        include 'cis'
    
        File<|title == '/etc/profile'|> {
            ensure => 'file',
            owner  => 'root',
            group  => 'root',
            mode   => '0600',
            source => 'puppet:///modules/profile/hadoop/etc/profile',
        }
    }
    

    详情请参阅the docs

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-12-26
      • 2012-09-22
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多