Ask Your Question
0

"require" ignore if "exec" succeed.

asked 2017-08-30 21:43:36 -0600

Sraw gravatar image
exec { "check_presence":
    command => "/bin/true",
    onlyif => '/usr/bin/test -e /path',
}

file {"/home/user/test.txt":
    ensure => file,
    require => Exec["check_presence"]
}

I can't figure out what's wrong with my script. I use puppet apply test.pp to run this script. But no matter /path exists or not, the file test.txt was created.

I was using puppet 3.4.3. Any help is appreciated.

edit retag flag offensive close merge delete

Comments

That is correct. With relationships you define resources' order _in_ _terms_ _of_ _time_. https://docs.puppet.com/puppet/latest/lang_relationships.html#syntax-relationship-metaparameters With Puppet, you can _not_ define a relationship “define resource X, only if resource Y executed”.

Kai Burghardt gravatar imageKai Burghardt ( 2017-08-31 04:34:46 -0600 )edit

@Kai Burghardt But could you check this answer https://serverfault.com/a/516919/428218, it says we can use onlyif in this way, and there are a lot of agreements in comment. I just wonder am I misunderstand this answer?

Sraw gravatar imageSraw ( 2017-08-31 20:12:13 -0600 )edit

Well, if so, then that's at least bad. That's bad style, you know, don't abandon Puppet's declarative paradigm.

Kai Burghardt gravatar imageKai Burghardt ( 2017-09-01 05:41:13 -0600 )edit

1 Answer

Sort by » oldest newest most voted
0

answered 2017-09-01 23:39:16 -0600

greynolds gravatar image

Hmmm...

Not sure what you are looking to accomplish. If it's to allow the execution of the exec file to initiate once when a file does not exist, then don't execute when the file does exist, then this will help.

exec { "check_presence": command => "/bin/true" onlyif => '/bin/grep -c /home/user /home/user/test.txt && exit 1 || exit 0' }

The intent of the meta parameter {'onlyif}, in this case, is to check to see if the file exists or not.

scan the /home/user directory for /home/user/test.txt if return a ( 1 ) exit out of the exec if this condition is not met then create the file based on your code block instructions.

I hope this helps

edit flag offensive delete link more

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: 2017-08-30 21:43:36 -0600

Seen: 116 times

Last updated: Sep 01