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 -0500

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 -0500 )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 -0500 )edit

1 Answer

Sort by ยป oldest newest most voted

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

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 -0500 )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 -0500 )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 -0500

Seen: 107 times

Last updated: Dec 19 '16