Ask Your Question
0

how to check whether file exist

asked 2014-01-09 10:51:01 -0600

mac gravatar image

Hi,

I had written a manifest code to check whether the directory /opt exist in ubuntu & centos systems as,

if $operatingsystem == 'RedHat && Ubuntu' {

file { "/opt": mode => 755, owner => root, group => root, ensure => directory, } } }

notify { "The 'opt' directory exist for Ubuntu & Centos servers.": }

Can anyone suggest a better manifest code as compared to mine as above.

Thanks

edit retag flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted
0

answered 2014-01-10 03:59:07 -0600

doc75 gravatar image

Hello,

For me you are not checking if the directory exit, but you ensure it exist after your manifest is run.

I would write it down like that with a case statement (not checked):

case $operatingsystem {
    'RedHat', 'Ubuntu': {
        file { "/opt": mode => 755, owner => root, group => root, ensure => directory, }->
        notify { "The 'opt' directory exist for Ubuntu & Centos servers.": }
    }
    default:            {}
}

Hope this helps.

edit flag offensive delete link more

Comments

thanks & how can the same code be written in rspec ?

mac gravatar imagemac ( 2014-01-10 09:19:56 -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

Stats

Asked: 2014-01-09 10:51:01 -0600

Seen: 307 times

Last updated: Jan 10 '14