Ask Your Question
1

How to get class evaluated just once

asked 2013-09-04 03:10:21 -0500

jaksky gravatar image

I wonder if there is some possibility to evaluate (include into catalog) some class just for the first time? To provide more info about the use case: During the installation there is a need to perform some step which in the following runs would cause a data loss and there is no way how ot get status of the resource.

Thx

edit retag flag offensive close merge delete

2 Answers

Sort by ยป oldest newest most voted
3

answered 2013-09-04 06:56:49 -0500

banjer gravatar image

updated 2013-09-04 06:58:52 -0500

The way I handle a "one-time operation", i.e. "please only run this at deployment time" is by putting everything in a shell script and calling it with Exec. The very last command in the script touches a file somewhere on the host, kind of like a lock file. Then you can tell the Exec to only run if the lock file doesn't exist.

class mymodule {
    # distribute the script file
    file { '/usr/local/bin/deployment.script.sh':
          owner   => 'banjer',
          group   => 'wheel',
          mode    => '500',
          source  => 'puppet:///modules/mymodule/deployment.script.sh/',
    }

    # only fire if /var/tmp/ive.been.deployed.lck ...
(more)
edit flag offensive delete link more
0

answered 2013-09-04 10:38:51 -0500

Ancillas gravatar image

updated 2013-09-04 10:40:55 -0500

You can drive this off of a custom fact if an Exec won't work. If you set a $first_boot fact to true on all new servers, you can then put your class in an if structure.

if $first_boot {
  include first_boot_code
}

At the end of your first_boot_code class, change the $first_boot fact to false.

I would implement $first_boot as an external fact in /etc/facter/facts.d/first_boot_facts.txt. Then you can change the content of the facts in the file using a File resource as the last step of your first_boot_code class.

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-09-04 03:10:21 -0500

Seen: 1,891 times

Last updated: Sep 04 '13