覆盖puppet模块中的参数

时间:2014-02-21 16:36:25

标签: puppet

我想覆盖基节点的参数。我想得到的是这样的模式:

# File manifests/nodes.pp
node myDefault {
    class { 'my::common::puppet_setup': 
        service => 'enable',
        pushable => 'disable',
    }
    # Do lots of default things ...
}
node 'myFirstNode' inherits myDefault {
    # Do something ...
}
node 'mySecondNode' inherits myDefault {
    class { 'my::common::puppet_setup::params':
        service => 'disable',
        pushable => 'enable',
    }
}

我理解了puppet文档,我可以通过编写这样的模块来完成这个:

# File modules/my/manifests/common/puppet_setup.pp
class my::common::puppet_setup (
    $pushable = $my::common::puppet_setup::params::pushable,
    $service  = $my::common::puppet_setup::params::service,
) inherits my::common::puppet_setup::params {
    # package that configures puppet node

    # input value validation
    validate_re($pushable, ['^enable$', '^disable$', '^ignore$', ])
    validate_re($service, ['^enable$', '^disable$', '^ignore$', '^cron$', ])

    # setup puppet, start or disable agent, put ssh keys for push ...

}

class my::common::puppet_setup::params {
    $pushable = 'enable'
    $service  = 'enable'
    $puppetserver = 'puppet.my.site.de'
    case $::osfamily {
        'Debian': {
        }
        default: {
            fail("not implemented yet for {::operatingsystem}")
        }
    }
}

puppet website上的文件说: 声明派生类时,会首先自动声明其基类(如果它尚未在其他地方声明)。

但是我得到了这个错误(添加了一些缩进):

mySecondNode# puppet agent --test --environment dev_my
Error: Could not retrieve catalog from remote server: 
  Error 400 on SERVER: Duplicate declaration:
    Class[My::Common::Puppet_setup::Params] is already declared;
    cannot redeclare at /.../puppet/manifests/nodes.pp:16 on node mySecondNode
Warning: Not using cache on failed catalog
Error: Could not retrieve catalog; skipping run

我正在阅读这一个星期,我猜我的理解在某处完全错了,尽管我使用了puppetlabs ntp模块作为例子。

我错过了什么?

2 个答案:

答案 0 :(得分:2)

您应该从http://docs.puppetlabs.com/puppet/latest/reference/lang_node_definitions.html

检查继承部分
  

Puppet将节点定义视为类。它不会将两者混合在一起然后编译混合;相反,它编译基类,然后编译派生类,它获取父范围和特殊权限,以修改基类中的资源属性。

一个好的解决方案是使用角色和个人资料,有一篇很棒的博客文章: http://garylarizza.com/blog/2014/02/17/puppet-workflow-part-2/

答案 1 :(得分:0)