puppetlabs-puppet_agent icon indicating copy to clipboard operation
puppetlabs-puppet_agent copied to clipboard

puppet agent include the APT class locking it and will make other .pp fail if they include apt

Open aqueos opened this issue 6 months ago • 0 comments

Describe the Bug

hi,

This module include the class apt but if it is called elsewhere with parameters this will conflict.

If included elsewhere on a node it will lead to :

Error while evaluating a Resource Statement, Duplicate declaration: Class[Apt] is already declared;

Expected Behavior

It should not think important class like the APT one is used only in the module as it can be used elsewhere with parameters and other things. a quick test can help i think ?

+      if !defined(Class['apt']) {
+          include apt
+      }

this seems enough to prevent this :)

Steps to Reproduce

Steps to reproduce the behavior: use in a node the apt class, then use the puppet agent module.

Environment

  • Version [e.g. 1.27.0]├── puppetlabs-puppet_agent (v4.20.1)
  • Platform [e.g. Ubuntu 18.04] debian 11

Additional Context

here is the patch i used:


diff --git a/modules/puppet_agent/manifests/osfamily/debian.pp b/modules/puppet_agent/manifests/osfamily/debian.pp
index 7cbd9d3e..e434f8fd 100644
--- a/modules/puppet_agent/manifests/osfamily/debian.pp
+++ b/modules/puppet_agent/manifests/osfamily/debian.pp
@@ -13,7 +13,9 @@ class puppet_agent::osfamily::debian {
     contain puppet_agent::prepare::package
   } else {
     if getvar('::puppet_agent::manage_repo') == true {
-      include apt
+      if !defined(Class['apt']) {
+          include apt
+      }
       if ($puppet_agent::is_pe and (!$puppet_agent::use_alternate_sources)) {
         $pe_server_version = pe_build_version()
         if $puppet_agent::source {

aqueos avatar Aug 06 '24 08:08 aqueos