简体   繁体   English

人偶覆盖模块上的文件资源

[英]puppet overriding file resource on a module

i am using this CIS module arildjensen/cis-puppet 我正在使用此CIS模块arildjensen / cis-puppet

and want to override the /etc/profile file declaration on the CIS module 并想要覆盖CIS模块上的/etc/profile文件声明

so i created this new manifest, following this 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',
      }
  }

however this still gives the error 但这仍然会导致错误

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

The syntax for a resource override is different from the syntax for a resource declaration. 资源覆盖的语法与资源声明的语法不同。 You're looking for this: 您正在寻找:

class profile::hadoop::settings inherits cis {

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

Syntactically, it's a resource reference (which makes sense) with an appended list of property overrides. 从语法上讲,它是一个资源引用(有意义),带有附加的属性覆盖列表。

That's the old-school way, of course. 当然,那是老派的方式。 Since at least Puppet 3.0, you can also perform overrides with a collector, in which case you don't need class inheritance: 从至少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',
    }
}

See the docs for full details. 有关完整的详细信息,请参阅文档

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM