A little annoyance in Puppet that appears to go way back.
When you manage yum repo files using the Yumrepo
resource, a duplicate definition can cause the rest of the manifest execution to fail. Take the following example.
yumrepo { 'puppetlabs-products': baseurl => "http://yum.puppetlabs.com/el/${osversion}/products/\$basearch", descr => "Puppet Labs Products El ${osversion} - \$basearch", enabled => '1', gpgcheck => '1', } file { '/etc/yum.repos.d/puppetlabs.repo': ensure => absent, }
This attempted to remove the “obsolete” file “puppetlabs.repo”, that is being managed by Puppetlab’s RPM package. The idea was to remove that file, and manage the repo with Yumrepo
resources. But if you try that, here’s what happens.
Info: Applying configuration version '1417605289' Info: mount[files]: allowing * access Error: Could not prefetch yumrepo provider 'inifile': Section "puppetlabs-products" is already defined, cannot redefine in /etc/yum.repos.d/puppetlabs-deps.repo Notice: /Stage[main]/Yum::Repo::Puppetlabs/File[/etc/yum.repos.d/puppetlabs.repo]/ensure: removed Error: /Stage[main]/Yum::Repo::Puppetlabs/Yumrepo[puppetlabs-deps-source]: Could not evaluate: No such file or directory - /etc/yum.repos.d/puppetlabs.repo ...
The result? The puppet run fails: it finds a duplicate Yumrepo
resource, as it pre-fetches all yum repos at the moment it’s started. For now, the only solution I found to get this working was to simply rename the Yumrepo
resource to something unique, after which the removal of the yumrepo-file works. It no longer tries to manage the yumrepo’s on a duplicate location.
yumrepo { 'puppetlabs-prod-products': baseurl => "http://yum.puppetlabs.com/el/${osversion}/products/\$basearch", descr => "Puppet Labs Products El ${osversion} - \$basearch", enabled => '1', gpgcheck => '1', } file { '/etc/yum.repos.d/puppetlabs.repo': ensure => absent, }
That works as you would expect: the next run, the code will still throw a “Could not prefetch yumrepo provider ‘inifile’: Section “puppetlabs-products” is already defined” error, but it will remove the File
resource. The run after that, the duplicate yumrepo name will not happen again since the .repo file is removed, and the run will succeed.
It’s not perfect, it’s not even beautiful, but it works.