Ask Your Question
0

WIndows Second run - how to identify

asked 2017-06-01 13:27:38 -0500

senthilvv28 gravatar image

We have a module which we need to run only one time, If its already performed we like to skip the run , is there a way to identity first run or second run

edit retag flag offensive close merge delete

1 Answer

Sort by » oldest newest most voted
0

answered 2017-06-02 09:59:29 -0500

DarylW gravatar image

A module should be designed to be idempotent. You should have the parts of your module able to verify that what they had done was already done. in execs, you use one of creates, onlyif, unless to check some condition on if the exec itself should run or not. If you are making a module, a classic pattern is to structure it as 'install', 'configure', 'service' pieces. In the 'install' phase, you make sure that the package/archive is installed and in place, in configure you set up any module based changes to the configuration (either modifying files in place or overwriting them from a template), and in 'service' you ensure that the service is running.

Ideally, you are installing something from a package, and you use the package resource to tell if it is correctly installed or not. Sometimes it is less than ideal, and you have to either run a 'one off' script or extract an archive (zip/tar), and you end up having to do some gymnastics. If you know that the install process creates a file, then you put the path to that file in the creates part of an exec, and it won't rerun. If you have some other way to verify that it is installed, you can put some simple logic in the unless or onlyif parameters.

https://docs.puppet.com/puppet/latest...

creates

A file to look for before running the command. The command will only run if the file doesn’t exist.

This parameter doesn’t cause Puppet to create a file; it is only useful if the command itself creates a file. exec { 'tar -xf /Volumes/nfs02/important.tar': cwd
=> '/var/tmp', creates => '/var/tmp/myfile', path => ['/usr/bin', '/usr/sbin',], }

In this example, myfile is assumed to be a file inside important.tar. If it is ever deleted, the exec will bring it back by re-extracting the tarball. If important.tar does not actually contain myfile, the exec will keep running every time Puppet runs.

https://docs.puppet.com/puppet/latest...

onlyif

If this parameter is set, then this exec will only run if the command has an exit code of 0. For example: exec { 'logrotate': path => '/usr/bin:/usr/sbin:/bin', onlyif => 'test du /var/log/messages | cut -f1 -gt 100000', }

This would run logrotate only if that test returned true.

Note that this command follows the same rules as the main command, such as which user and group it’s run as. This also means it must be fully qualified if the path is not set.

It also uses the same provider as the main command, so any behavior that differs by provider will match.

Also note that onlyif can take an array as its value, e.g.: onlyif => ['test -f /tmp/file1', 'test -f /tmp/file2'],

This will only run the exec if all conditions in the array return true.

https://docs.puppet.com/puppet/latest...

unless

If this parameter is set, then this exec will ...

(more)
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-06-01 13:27:38 -0500

Seen: 28 times

Last updated: Jun 02