Ask Your Question

How can I define an action based on a current state?

asked 2013-09-06 14:13:15 -0500

Rob Ogilvie gravatar image

I want to define some actions based on current state, but am having a difficult time figuring out how to get current state out of some built-in types.

Specifically, I want to execute a command if a package is not a specific version.

I haven't had any luck getting the current version out of a package.


edit retag flag offensive close merge delete

2 answers

Sort by ยป oldest newest most voted

answered 2013-09-06 14:28:08 -0500

llowder gravatar image

updated 2013-09-06 15:34:36 -0500

The TL;DR version is, you can't. Puppet isn't a shell script, but is for managing state. The basic idea is that you define the end state and let Puppet worry about how to get there.

That being said, you do have a few options.

  • You can shell out to an exec and have a script that checks the version and does whatever.
  • You can use an orchestration tool such as MCollective

If you can describe what the end goal is, I (or someone else) can provide some better ways to accomplish that goal.


Use a file ... (more)

edit flag offensive delete link more


Thanks. I want to install a one-off RPM file on my OEL6 boxen without putting it into my local yum repository (my upstream provider hasn't mainlined the bugfix RPM ...(more)

Rob Ogilvie gravatar imageRob Ogilvie ( 2013-09-06 14:32:28 -0500 )edit

Or just host the rpm on an nfs share / internal web site and use the source attribute for package. Or host the rpm on the puppet server, and use `file ...(more)

jonuwz gravatar imagejonuwz ( 2013-09-06 15:09:47 -0500 )edit

You can't pass arguments to the RPM command, and since the one-off was a lower version, it didn't work. I ended up scripting it out using a flag ...(more)

Rob Ogilvie gravatar imageRob Ogilvie ( 2013-09-06 16:01:03 -0500 )edit

answered 2013-09-12 08:17:09 -0500

rahul khengare gravatar image

updated 2013-09-12 08:21:13 -0500

You can use exec resource with onlyif property for conditional execution of command.

Refer following demo exec resource, Here i execute [ "ls /root/" ] command only if ruby package with version is present.

In onlyif property we execute command [ rpm -qi ruby | grep -w Version | grep -w "" ] which returns true if command returns same package version otherwise return false.

If command in onlyif returns true then exec execute the main command otherwise it skip the exec resource from execution at puppet run.

exec {"conditional execution of command":
     path => "/usr/bin:/usr/sbin:/bin ...
edit flag offensive delete link more


Beautiful! I modified my first recipe to utilize onlyif to clean it up a bit. Thanks!

Rob Ogilvie gravatar imageRob Ogilvie ( 2013-09-12 10:12:37 -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: 2013-09-06 14:13:15 -0500

Seen: 159 times

Last updated: Sep 12 '13