Ask Your Question
0

Tidy a directory, but excluding items in an array

asked 2015-09-08 03:23:53 -0500

giggsey gravatar image

updated 2015-09-09 03:37:21 -0500

Is there anyway I can Tidy a directory, but exclude certain folders from being deleted?

I have an array of folders which should exist, and I want to remove anything else that doesn't match those

--

I've tried

$permittedVersions = ['a', 'b']

  tidy { "/software/releases":
    age => '1s',
    rmdirs => true,
    recurse => true,
    matches => [ !$permittedVersions ],
   }

And I have folders a, b, c and d.

However, it errors with:

Failed to generate additional resources using 'generate': can't convert false into String

edit retag flag offensive close merge delete

2 Answers

Sort by ยป oldest newest most voted
0

answered 2015-09-08 09:48:57 -0500

Hi,

looking at tidy resource it appears you can use a glob - so could try to do a:

tidy { "/directoryname":
   age     => "2w",
   rmdirs => true,
   recurse => 1,
   matches => [ !list ]

}

edit flag offensive delete link more

Comments

I'm getting an error: `Failed to generate additional resources using 'generate': can't convert false into String`. I've edited my main post showing what I was running

giggsey gravatar imagegiggsey ( 2015-09-09 03:37:59 -0500 )edit
0

answered 2015-09-09 11:55:40 -0500

johnnyb04 gravatar image

updated 2015-09-09 12:16:42 -0500

Another way of doing this is by using the file resource with the purge attribute. You have to specifically manage your needed files though (e.g. a & b). Here is what I suggest...

file { '/directoryname/a':
  ensure => present,
} 
file { '/directoryname/b':
  ensure => present,
} 
file { '/directoryname':
  ensure => directory,
  purge => true, #Deletes files in directory
  recurse => true, #Files under sub-folders are deleted
  force => true; #Sub-folders are deleted as well
}
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

1 follower

Stats

Asked: 2015-09-08 03:23:53 -0500

Seen: 371 times

Last updated: Sep 09 '15