Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Duplicate declaration due to contain ::apt #110

Closed
HT43-bqxFqB opened this issue Oct 27, 2017 · 6 comments
Closed

Duplicate declaration due to contain ::apt #110

HT43-bqxFqB opened this issue Oct 27, 2017 · 6 comments
Assignees

Comments

@HT43-bqxFqB
Copy link

In one of our profile classes for managing apt we call unattended_upgrades and the apt class. The change in Version 3.0.0 to use contain ::apt causes a duplicate declaration error.

Affected Puppet, Ruby, OS and module versions/distributions

  • Puppet: 4.10.X
  • Ruby:
  • Distribution: Ubuntu >= 14
  • Module version: 3.0.0

How to reproduce (e.g Puppet code you use)

Call unattended_upgrades and apt class in the same Puppet class code without hiera:

# install and manage unattended upgrades
class {'unattended_upgrades':
    enable        => bool2num($unattended_upgrades),
    auto          => {
        reboot => true,
        remove => true,
        clean  => 7,
    },
    origins       => [
        '${distro_id}:${distro_codename}-security',
        '${distro_id}:${distro_codename}-updates',
        '${distro_id}:${distro_codename}-backports',
        'Puppetlabs:${distro_codename}',
    ],
    minimal_steps => false,
}

# basic configuration
class { 'apt':
    purge => {
        'sources.list'   => true,
        'sources.list.d' => true,
        'preferences'    => true,
        'preferences.d'  => true,
    },
    proxy => {
        'host' => $proxy_host,
        'port' => $proxy_port,
    },
}

What are you seeing

Could not retrieve catalog from remote server: Error 500 on SERVER: Server Error: Evaluation Error: Error while evaluating a Function Call, Duplicate declaration: Class[Apt] is already declared; cannot redeclare at /etc/puppetlabs/code/environments/development/modules/profiles/manifests/base/apt.pp:132 at /etc/puppetlabs/code/environments/development/modules/profiles/manifests/base/apt.pp:132:5 on node yxz

Any additional information you'd like to impart

Is there a way to work around this in my code?

@alexjfisher alexjfisher self-assigned this Oct 27, 2017
@alexjfisher
Copy link
Member

@HT43-bqxFqB I've changed the contain to include and this is included in new release 3.0.1

In your code, switch the order of unattended_upgrades and apt in your manifest (physical order in the file, not require/before style ordering). You should no longer get a duplicate resource error.

@HT43-bqxFqB
Copy link
Author

Works perfect now, thanks! I don't get why the order in the manifest matters due to puppet being stateless o_O
Thanks again!

@alexjfisher
Copy link
Member

The evaluation order can be important when a catalog is being compiled. A class can be ‘ ‘included’ multiple times, but once it’s been added to the catalog, you can’t declare it ‘resource-style’. When an agent applies a catalog, then it’s all about the resource relationships.

@alexjfisher
Copy link
Member

Your other option was to use hiera to configure apt and then not explicitly declare it yourself at all.

@HT43-bqxFqB
Copy link
Author

I was not aware that the evaluation order on compilation was important. Thanks for that tip!

@alexjfisher
Copy link
Member

yeah, try referencing variables from other classes before they've been parsed... :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants