Ask Your Question

How do I recursively set perms on files while leaving the permissions of subdirectories alone?

asked 2016-12-14 14:27:43 -0600

fiddle_jake gravatar image

I'd like to remove group write and world write on all files in a directory tree while leaving permissions of subdirectories alone. Is there a way to do this in puppet?


edit retag flag offensive close merge delete


Puppet is about describing the state of the system in an idempotent way. What you are describing doesn't create the same results if run on two different systems, or the same system with different sets of files/directories. I'm not sure that there is an easy way to achieve what you want.

DarylW gravatar imageDarylW ( 2016-12-15 07:18:12 -0600 )edit

I'm not a `find(1)` aficionado, but something like `find /foo -perm -a=w -perm -g=w -type f -exec chmod g-w,a-w {}` in an exec resource? However, as DarylW wrote, it's not the style you do with PP. More about PP's exec resource:

Kai Burghardt gravatar imageKai Burghardt ( 2016-12-15 18:17:48 -0600 )edit

2 Answers

Sort by ยป oldest newest most voted

answered 2018-08-14 06:26:46 -0600

Almost, you can have it manage only the top-level entries in the directory:

Setting recurselimit => 1 will manage files and directories that are directly inside the directory, but will not manage the contents of any subdirectories.

file { '/my/directory':
  ensure => directory,
  recurse => true,
  recurselimit => 1,
  mode => 'g-w,o-w'
edit flag offensive delete link more

answered 2016-12-19 17:53:58 -0600

fiddle_jake gravatar image

Thanks to everyone who offered an answer. I had written a module that used the file resource written below

file { '/some/directory': mode => 'g-w,o-w', recurse => true, }

It works great removing group write and world write from both files and directories except, I want it to not operate on directories.

Maybe it can't be done?

edit flag offensive delete link more


That's why you had to use `find(1)`. Unless you know all the sub-directories in advance: Then you could write proper `file` resources for them (which take precedence since they're more specific).

Kai Burghardt gravatar imageKai Burghardt ( 2016-12-19 18:16:42 -0600 )edit

or you could create a custom fact that would 'find' all of the directories, and then you could create your resources from that, but it is not a 'clean' way to do it.

DarylW gravatar imageDarylW ( 2016-12-20 09:48:49 -0600 )edit

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: 2016-12-14 14:27:43 -0600

Seen: 480 times

Last updated: Aug 14