Ask Your Question

Purging files not being managed or created by augeas (yum.repos.d)

asked 2013-09-17 01:13:18 -0600

asktbt gravatar image

updated 2013-09-17 05:57:24 -0600

Creating file resources using augeas works fine so far. I'm creating the yum configuration in /etc/yum.repos.d from hiera via


        baseurl   : <a href="$releasever-$basearch/RPMS.local/">$releasever-$basearch/RPMS.local/</a>
        descr     : CentOS-$releasever


     $yumrepo_hash = hiera_hash('system::yumrepos', undef)
     create_resources(yumrepo, $yumrepo_hash, $defaults)

This leaves however old entries and other files in the directory /etc/yum.repos.d untouched. Some of them having either the wrong specification or the wrong syntax, those needs to be removed.
When configuring

    file ...
edit retag flag offensive close merge delete

3 Answers

Sort by » oldest newest most voted

answered 2013-09-17 06:07:59 -0600

asktbt gravatar image

updated 2013-09-17 06:14:18 -0600

Thanks for the suggestion. I was wrapping my head a bit more around it and solved it the following way:

  1. I introduced an additional parameter that per default doesn't do anything.
  2. If specified, it will create file resources with the right filenames in /etc/yum.repos.d (basically empty) files which then will be edited by the augeas tool correctly. All other "non-specified" files will be purged by the file/directory resource then. In case anybody facing the similar problem, here's the code:


    system::params::yumrepos_keep  :
      - repo1
      - repo2

        baseurl   : <a href="http://mrepo.example ...
edit flag offensive delete link more


Thank you! simple and does the job.

Andrey gravatar imageAndrey ( 2014-01-09 05:30:10 -0600 )edit

answered 2013-09-19 13:33:21 -0600

illsci gravatar image

updated 2013-09-19 13:35:21 -0600

I'm trying to do something similar but I haven't figured out how to make it not remove all the files and add them right back again.

class yum::repos (
    $config = undef,
) {

    $defaults = {
        enabled  => '1',
        gpgcheck => '0',
        priority => '20',
        'require' => File['/etc/yum.repos.d'],

    # Remove all unmanaged repos
    file {'/etc/yum.repos.d':
        recurse => true,
        purge   => true,

    if $config == undef {
        $repo_config = hiera_hash('yum::repos', undef)
    else {
        $repo_config = $config

    create_resources(yumrepo, $repo_config, $defaults)
edit flag offensive delete link more


That's why I introduced the other parameter that defines a file resource separately for the repositories to keep. By just creating the resource for every `*.repo` file Puppet knows ...(more)

asktbt gravatar imageasktbt ( 2013-09-26 02:02:16 -0600 )edit

answered 2013-09-17 03:25:44 -0600

golja gravatar image

updated 2013-09-17 03:26:30 -0600

For purge=>true to work as you were expected you at least need define resource or some other related resources. From the documentation

When recursively duplicating an entire directory with the source attribute, purge => true will automatically purge any files that are not in the source directory. When managing files in a directory as individual resources, setting purge => true will purge any files that aren’t being specifically managed.

To solve your problem there is always the old dirty exec resource where you can write an custom script, which will make sure that your folder is clean as expected. Not ... (more)

edit flag offensive delete link more

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account.

Add Answer

Question Tools



Asked: 2013-09-17 01:13:18 -0600

Seen: 879 times

Last updated: Sep 19 '13