Puppet: could not prefetch yumrepo provider ‘inifile’: Section is already defined, cannot redefine

Want to help support this blog? Try out Oh Dear, the best all-in-one monitoring tool for your entire website, co-founded by me (the guy that wrote this blogpost). Start with a 10-day trial, no strings attached.

We offer uptime monitoring, SSL checks, broken links checking, performance & cronjob monitoring, branded status pages & so much more. Try us out today!

Profile image of Mattias Geniar

Mattias Geniar, December 03, 2014

Follow me on Twitter as @mattiasgeniar

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.



Want to subscribe to the cron.weekly newsletter?

I write a weekly-ish newsletter on Linux, open source & webdevelopment called cron.weekly.

It features the latest news, guides & tutorials and new open source projects. You can sign up via email below.

No spam. Just some good, practical Linux & open source content.