我有一个主要的puppet类被添加到我的networking中的所有服务器,我们称之为:profile :: base.pp:
class profile::base { ... $agent_zbx_templates = ['OS Linux'] ... include profile::zabbix::agent }
我具体节点的hiera文件我有: classes: - profile::haproxy
和类configuration文件:: haproxy.pp我想添加一些东西到profile :: base.pp中定义的$ agent_zbx_templates,例如:
class profile::haproxy { $local_agent_zbx_templates = $profile::base::agent_zbx_templates + ['APP HAProxy'] class {'profile::base': agent_zbx_templates => $local_agent_zbx_templates } }
当然,当我尝试在节点上执行puppet agent -t时,我已经收到: [root@stress1 ~]# puppet agent -t Info: Using configured environment 'production' Info: Retrieving pluginfacts Info: Retrieving plugin Info: Loading facts Error: Could not retrieve catalog from remote server: Error 500 on SERVER: Server Error: Evaluation Error: Error while evaluating a Resource Statement, Evaluation Error: Error while evaluating a Resource Statement, Duplicate declaration: Class[Profile::Base] is already declared; cannot redeclare at /etc/puppetlabs/code/environments/production/modules/profile/manifests/haproxy.pp:48 at /etc/puppetlabs/code/environments/production/modules/profile/manifests/haproxy.pp:48:3 on node stress1.lb.dc2 Warning: Not using cache on failed catalog Error: Could not retrieve catalog; skipping run [root@stress1 ~]# puppet agent -t Info: Using configured environment 'production' Info: Retrieving pluginfacts Info: Retrieving plugin Info: Loading facts Error: Could not retrieve catalog from remote server: Error 500 on SERVER: Server Error: Evaluation Error: Error while evaluating a Resource Statement, Evaluation Error: Error while evaluating a Resource Statement, Duplicate declaration: Class[Profile::Base] is already declared; cannot redeclare at /etc/puppetlabs/code/environments/production/modules/profile/manifests/haproxy.pp:48 at /etc/puppetlabs/code/environments/production/modules/profile/manifests/haproxy.pp:48:3 on node stress1.lb.dc2 Warning: Not using cache on failed catalog Error: Could not retrieve catalog; skipping run
我怎样才能从另一个类更改agent_zbx_templates(从configuration文件:: base)?
问候,第。
你不能在同一个节点上两次声明一个类。
但是,您可以执行的操作是添加节点或特定于环境的hiera文件。 Hiera通过层次结构并使用它find的第一个声明,而忽略以后重复的声明。
hiera.yaml:
:hierarchy: - "node/%{::fqdn}" - "environment/%{::environment}" - ...
然后,在您的hiera datadir中创build文件夹node ,例如: /etc/puppetlabs/hieradata/node 。 每当你把一个名为fqdn的yaml文件放到那里,那里的类声明就会被使用,而同一个类的声明将被忽略。