Ask Your Question
2

facter variable comparison with onlyif

asked 2013-06-21 10:59:59 -0500

stargeek71 gravatar image

updated 2013-06-21 11:05:04 -0500

I have a runexec that I only want to run once if the timezone is set incorrectly. I am using the Facter variable of timezone. Here is a snippet of the puppet code and also a snippet of the log file. I don't want to run the exec command if the timezone is set to UTC. I am just having a problem with the syntax of the onlyif command how do you compare a variable to a value?

exec { "hwclock":

    command => "hwclock --systohc",
    path    => "/usr/sbin/",
    onlyif  => "($timezone = 'UTC')"
 }

Jun 21 15:29:58 hp92 puppet-agent[26095]: (/Stage[main ... (more)

edit retag flag offensive close merge delete

2 Answers

Sort by ยป oldest newest most voted
0

answered 2013-06-21 13:34:04 -0500

stargeek71 gravatar image

Was able to resolve it taking a slightly different approach.

exec { "hwclock": command => "hwclock --systohc", path => "/usr/sbin/", unless => '/bin/date | /bin/grep UTC', }

Thanks to J. Arundel and his book Puppet 3 Beginners Guide for some guidance.

edit flag offensive delete link more
0

answered 2013-06-21 14:40:21 -0500

GregLarkin gravatar image

The other option you have is the following:

exec { "hwclock":
    command => "hwclock --systohc",
    path    => "/usr/sbin/",
    onlyif  => 'test "$timezone" = "UTC"'
}

This will be slightly faster than using date piped to grep. You can find more details about controlling Puppet exec resources in the Puppet Cookbook.

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: 2013-06-21 10:59:59 -0500

Seen: 2,704 times

Last updated: Jun 21 '13