Skip to content

ensure_package existing resource detection #1252

Closed
@suchAdemon

Description

@suchAdemon

Use Case

supported puppet modules use sometimes the ensure_package function, which leads to a duplicate declaration error if you have it already defined in another manifest which gets included during the catalog build.

Describe the Solution You Would Like

the function ensure_package could check, as it does already for the packages puppet and facter, if it is somewhere defined in the current build catalog, to allow the defined resources from the manifest to be used instead of the ensure_package function.

Describe Alternatives You've Considered

I have thought about patching the upstream puppetlabs-apt module by adding a if condition with something like if ! (defined(Package['<packagename>']) { but that would mean on each update of the modules I would need to take care of getting back my change.
Another solution could be, that I place an if condition in front of the include command based on the puppet role which is used.
Both are not a really nice to have, but would work.

Additional Context

Found it while using the puppetlabs-apt module which uses ensure_package(['gnupg']), also I have a package resource which is already defined in an existing manifest. As soon both are used for the same catalog build, it runs into a duplicate declaration error.

puppetlabs-apt: v8.4.1
puppetlabs-stdlib: v8.2.0

  package { 'gnupg':
    ensure  => installed,
    require => Exec['apt_update'],
  }

Error:

Evaluation Error: Error while evaluating a Resource Statement, Evaluation Error: Error while evaluating a Resource Statement, Duplicate declaration: Package[gnupg] is already declared at (file: /data/puppet/environments/production/modules/apt/manifests/init.pp, line: 365); cannot redeclare (file: /data/puppet/environments/production/modules/defaults/manifests/packages/gnupg.pp, line: 6) (file: /data/puppet/environments/production/modules/defaults/manifests/packages/gnupg.pp, line: 6, column: 3) on node puppettest1.internal.testdomain

With this extension of ensure_package, puppet would make sure that the defined attributes on the package resource are getting used instead of "just" an ensure => present/installed as things like that are sometimes required.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions