voxpupuli / puppet-yum

Puppet module for Yum
https://forge.puppet.com/puppet/yum
MIT License
16 stars 101 forks source link

Section "cr" is already defined, cannot redefine #97

Closed TJM closed 5 years ago

TJM commented 6 years ago

Affected Puppet, Ruby, OS and module versions/distributions

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

      include ::yum
      # Purge?
      resources { 'yumrepo':
        purge => true,
      }
      # RPM GPG Keys
      create_resources('yum::gpgkey', $rpm_gpg_keys)
      # Resource Ordering
      Yumrepo <| |> -> Yum::Gpgkey <| |> -> Package <| provider != 'rpm' |>

NOTE: $rpm_gpg_keys=>(epel gpg key) until PR96 is in :)

What are you seeing

After doing yum upgrade from 7.3 -> 7.4, the centos-release package automatically created the "default' /etc/yum.repos.d files. (specifically /etc/yum.repos.d/CentOS-*.repo)

The following error comes up during a puppet run:

Error: /Stage[main]/Profile::Linux::Software/Resources[yumrepo]: Failed to generate additional resources using 'generate': Section "cr" is already defined, cannot redefine (file: /etc/yum.repos.d/CentOS-CR.repo)

What behaviour did you expect instead

Shouldn't the resources { 'yumrepo': purge => true } take care of removing that duplicate?

Output log

See Error above

Any additional information you'd like to impart

Asked this question in Puppet Community Slack too, I think it may be a "puppet" bug, but I am considering that we should maybe try to create the "default" OS files as the same filenames as they would be created by the -release package, so that they are not duplicated? (if that is possible even)

[root@linux01 yum.repos.d]# rpm -ql centos-release | grep repo
/etc/yum.repos.d/CentOS-Base.repo
/etc/yum.repos.d/CentOS-CR.repo
/etc/yum.repos.d/CentOS-Debuginfo.repo
/etc/yum.repos.d/CentOS-Media.repo
/etc/yum.repos.d/CentOS-Sources.repo
/etc/yum.repos.d/CentOS-Vault.repo
/etc/yum.repos.d/CentOS-fasttrack.repo

They are listed as "config" files, so they would not be overwritten during upgrade.

~tommy

TJM commented 6 years ago

OK, so upon further investigation, its the resources { 'yumrepo': purge => true } that is causing the error:

[root@linux01 ~]# puppet apply -e 'resources { "yumrepo": purge => true }'
Notice: Compiled catalog for linux01.vagrant.local in environment vagrant in 0.10 seconds
Error: /Stage[main]/Main/Resources[yumrepo]: Failed to generate additional resources using 'generate': Section "cr" is already defined, cannot redefine (file: /etc/yum.repos.d/CentOS-CR.repo)
Notice: Applied catalog in 0.08 seconds

However, I wonder why none of the others (base, updates, etc) caused this error too? Why CR? anyone?

dhoppe commented 5 years ago

I need more information about how you added the CR repository. It might collide with the files from data/.

FYI: I explained in issue #94 how to remove repositories.

TJM commented 5 years ago

Steps to reproduce...

TJM commented 5 years ago

So, I think based on everything else I have seen, the actual problem is the "yumrepo" type/provider. This module could workaround this issue using file resource backing and build the purge option in, rather than depending on the resources { yumrepo: purge => true }.

Alternatively, the "cause" of this problem, which is an environment specific packer build script that removes all files from /etc/yum.repos.d, could be adjusted to truncate the file instead of removing it, which, since it is a "config" file in the repo, would not be overwritten.

I am going to close this one.

Thanks, Tommy

TJM commented 5 years ago

One other note, as of Puppet 6, the yumrepo resource type finally has a "target" parameter (that doesn't say not to use it) .. so the target could be set to the "expected" filename from the OS packages:

$ rpm -qV centos-release
missing   c /etc/yum.repos.d/CentOS-Base.repo
missing   c /etc/yum.repos.d/CentOS-CR.repo
missing   c /etc/yum.repos.d/CentOS-Debuginfo.repo
missing   c /etc/yum.repos.d/CentOS-Media.repo
missing   c /etc/yum.repos.d/CentOS-Sources.repo
missing   c /etc/yum.repos.d/CentOS-Vault.repo
missing   c /etc/yum.repos.d/CentOS-fasttrack.repo
TJM commented 4 years ago

If anyone else is being bit by this, instead of deleting the files in /etc/yum.repos.d, truncate them (make them empty). As they are "config" files, they will not be replaced during upgrades unless they are missing.

for file in /etc/yum.repos.d/CentOS-*; do cat /dev/null > $file; done

... then you can continue to use any "custom" files you have created. :)

~tommy