Ask Your Question

how to check file has link in puppet

asked 2015-05-14 07:12:19 -0600

Chutki gravatar image


I have below code


I want to remove "/etc/testlocal/init.d", so before I delete this folder wanna check for file link existence first

/etc/test.d/init.d/file -> /etc/testlocal/init.d/file.

I surfed net to convert into puppet, but didn't find any.

want to know is it possible in puppet.

edit retag flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted

answered 2015-05-14 22:54:11 -0600

GregLarkin gravatar image

updated 2015-05-18 17:17:30 -0600

You don't need to check for existence of the link, you just need to write your code like this:

$filelist = [ $abc, "${abc}/file", "${def}/file" ]
file { $filelist:
  ensure => absent,

Add more files to that list that you want to ensure are deleted.

Remember always that your Puppet code defines the desired state of the machine. Therefore, you have to write Puppet code to transform your machine from its current state to the desired state. Once you do that, Puppet will continue to keep that machine in the desired state every time the agent runs.


Since you are using the tidy resource, you have to make sure that you pass the recurse and rmdirs attribute, like so:

tidy { $abc:
  recurse => true,
  rmdirs  => true,

Assuming $abc contains directory path, that tidy resource will remove all files and directories within the directory, then remove the directory itself.

edit flag offensive delete link more


I used tidy resource and it deleted all the files under $abc, but if there is any directory under $abc its not removing. so tidy wont clean directory, its only meant for file clean up?

Chutki gravatar imageChutki ( 2015-05-15 13:12:25 -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

1 follower


Asked: 2015-05-14 07:12:19 -0600

Seen: 334 times

Last updated: May 18 '15