Ask Your Question

either a directory or a link

asked 2016-08-05 11:32:17 -0500

erichymowitz gravatar image

Short question -- can I define a puppet rule that says "If this directory exists, then leave it alone. If this directory does not exist, create a symlink" ?

Long unimportant backstory:

Most of my machines are running openldap . Most of those machines have their root certificates stored in /etc/openldap/cacerts . But a few machines, for whatever reason, are using /etc/openldap/certs instead. I don't want to change those machines -- they are working correctly and I want to keep them that way.

Puppet is installing new certificates into /etc/openldap/cacerts , and it fails when the directory does not exist.

So on machines where the cacerts directory exists, I don't want to do anything. I just want to know the directory is there.

But if the cacerts directory does not exist, I don't want to create a new empty directory. I want to soft-link it to the existing certs directory.

Can puppet manage that for me?

edit retag flag offensive close merge delete


I guess, you don't have to check for if the directory exists. If you check for either of the case it will do the work for you. Just checking if directory does not exist is enough. You can achieve this using file resource with link attribute. Please try if this helps.

rajeevsharma gravatar imagerajeevsharma ( 2016-08-05 12:55:25 -0500 )edit

"Check for either of the case"? how do i do that?

erichymowitz gravatar imageerichymowitz ( 2016-08-05 13:15:33 -0500 )edit

Please find my answer below.

rajeevsharma gravatar imagerajeevsharma ( 2016-08-05 15:00:29 -0500 )edit

1 Answer

Sort by ยป oldest newest most voted

answered 2016-08-05 15:10:43 -0500

rajeevsharma gravatar image

updated 2016-08-10 10:19:57 -0500

Checking only cacerts directory exists or not will do work for you. You don't have to worry about if it doesn't not exist. In fact, you handle both the cases in just one resource (it's like if condition). For example:

exec { 'create symlink':
command => 'ln -s /etc/openldap/certs /etc/openldap/cacerts',
unless  => 'test  -d /etc/openldap/cacerts',
path => ['/usr/bin', '/bin', /usr/sbin', '/sbin']

Above example will help you to create a soft link of cacerts if it does not exist. Hope it helps.

edit flag offensive delete link more


thanks. i'll try this out and see how it goes.....

erichymowitz gravatar imageerichymowitz ( 2016-08-05 15:19:07 -0500 )edit

sadly, i don't have time for testing right now. but it looks like it should work. thank you. i'll put this in a "reminder" for later.

erichymowitz gravatar imageerichymowitz ( 2016-08-10 07:10:31 -0500 )edit

"exect" ? is that a typo? or something i've never seen before?

erichymowitz gravatar imageerichymowitz ( 2016-08-10 07:11:27 -0500 )edit

sorry.. that was a typo. I''ll correct my answer with "exec". Thanks for pointing this out.

rajeevsharma gravatar imagerajeevsharma ( 2016-08-10 10:19:33 -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

1 follower


Asked: 2016-08-05 11:32:17 -0500

Seen: 60 times

Last updated: Aug 10 '16