Duplicate resource declaration

Puppet builds our catalogs based on every resource declared in our manifests. In good Puppet code design, we have classes that include or contain other classes. During development, it's not uncommon to sometimes attempt to declare a resource that has been declared in a class that's already applied on the system. By design, Puppet will fail on a duplicate resource declaration, and for a good reason: How can the catalog decide which resource is the right resource to apply? In the following example, a resource is declared in two separate classes being applied to my node:

[root@pe-puppet-master production]# puppet agent -t
Info: Using configured environment 'production'
Info: Retrieving pluginfacts
Info: Retrieving plugin
Info: Retrieving locales
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, Duplicate declaration: File[/var/log/custom] is already declared at (file: /etc/puppetlabs/code/environments/production/modules/profile/manifests/baseline.pp, line: 6); cannot redeclare (file: /etc/puppetlabs/code/environments/production/modules/profile/manifests/logging.pp, line: 3) (file: /etc/puppetlabs/code/environments/production/modules/profile/manifests/logging.pp, line: 3, column: 3) on node pe-puppet-master
Warning: Not using cache on failed catalog
Error: Could not retrieve catalog; skipping run

In the preceding case, I had my logging directory set in my baseline profile. I iterated and designed a whole profile around logging, and included my directory in the logging profile. To fix this error, I'll simply remove the custom logging directory resource from my baseline profile.

If you need to declare a resource, and potentially use it in multiple manifests, you may want to use a virtual resource.. Chapter 9, Exported Resources covers virtual resources, as well. 
..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
18.218.228.99