简体   繁体   English

使用继承时覆盖人偶类

[英]Overriding a Puppet Class when using Inheritance

I'm trying to use class inheritance for puppet. 我正在尝试对木偶使用类继承。 There is a base class named foo and an inherited class named bar . 有一个名为foo的基类和一个名为bar的继承类。 Overriding file or package resources are quite fine and works properly. 覆盖filepackage资源非常好并且可以正常工作。 But at the same time i'm using a custom module for configuring sudo . 但是同时我正在使用自定义模块来配置sudo

The problem arises when i try to override sudo class from inside class bar . 当我尝试从类bar内部重写sudo类时,就会出现问题。 Puppet classes are as follows: 木偶类如下:

 class foo {
  $nrpe_plugin_pkgs = [ .... ]

  service { 'nrpe service':
    ..
  }

  package { $nrpe_plugin_pkgs:
    ..
  }

  file { '/etc/nagios/nrpe.cfg':
    ..
  }

  file { '/etc/resolv.conf':
    ..
  }

  class { 'sudo':
    purge               => true,
    config_file_replace => true,
  }

  sudo::conf { 'sudo_conf':
    priority => 10,
    content  => [
      '%gr1 ALL=(userfoo) NOPASSWD: ALL',
      '%gr1 ALL=(root)  NOPASSWD: /usr/bin/wbinfo *',
    ]
  }
}


class bar inherits foo {
  File['/etc/resolv.conf'] {
    ..
  }

  sudo::conf { 'sudo_conf':
    priority => 10,
    content  => [
      '%gr2     ALL=NOPASSWD:/bin/chown userbar\:gr2 /dirbar/*',
      '%gr2     ALL=NOPASSWD:/bin/chown -R userbar\:gr2 /dirbar/*',
      '%gr2     ALL=NOPASSWD:/bin/chmod * /dirbar/*',
    ]
  }
}

I just want to customize only resolv.conf and sudo config, but i'm getting error as follows: 我只想自定义resolv.confsudo配置,但是出现如下错误:

Error while evaluating a Resource Statement, Evaluation Error: Error while evaluating a Resource Statement, Duplicate declaration: Sudo::Conf[sudo_conf] is already declared in file /etc/puppetlabs/code/environments/foobar_servers/manifests/foobar.pp:80; 评估资源声明时出错,评估错误:评估资源声明时出错,重复声明:在文件/etc/puppetlabs/code/environments/foobar_servers/manifests/foobar.pp:80中已经声明了Sudo :: Conf [sudo_conf] ; cannot redeclare at /etc/puppetlabs/code/environments/foobar_servers/manifests/foobar.pp:335 at /etc/puppetlabs/code/environments/foobar_servers/manifests/foobar.pp:335:3 on node foobartest01 无法在节点foobartest01上的/etc/puppetlabs/code/environments/foobar_servers/manifests/foobar.pp:335:3上的/etc/puppetlabs/code/environments/foobar_servers/manifests/foobar.pp:335处重新声明

/etc/sudoers.d/10_sudo_conf file expected to be created. 预期将创建/etc/sudoers.d/10_sudo_conf文件。 How can i achieve that? 我该如何实现?

Using: Puppet 4.9 Community version. 使用:人偶4.9社区版本。

Any help appreciated. 任何帮助表示赞赏。

The resolv.conf override works here, because you're using the correct syntax : resolv.conf重写在这里适用,因为您使用的是正确的语法

class bar inherits foo {
  File['/etc/resolv.conf'] {
    ..
  }

But the syntax for the next line where you try to override is different, so it fails: 但是您尝试覆盖的下一行的语法不同,因此失败:

sudo::conf { 'sudo_conf':

This is the syntax to declare a new resource (hence why you get a duplicate error) rather than to override an existing resource . 这是声明新资源 (因此为什么会出现重复错误)而不是覆盖现有资源的语法。 It should be: 它应该是:

Sudo::Conf['sudo_conf'] {
  priority => 10,
  content  => [
    '%gr2     ALL=NOPASSWD:/bin/chown userbar\:gr2 /dirbar/*',
    '%gr2     ALL=NOPASSWD:/bin/chown -R userbar\:gr2 /dirbar/*',
    '%gr2     ALL=NOPASSWD:/bin/chmod * /dirbar/*',
  ]
}

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

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