Example of generate(‘…’) use in puppet

puppet

I am trying to learn how to use puppet, following along with their Quick Start Guide.

I would like to add a time stamp using generate:

$timestamp = generate('/bin/date')

class helloworld::motd {
    file { '/etc/motd':
    owner => 'root',
    group => 'root',
    mode => '0644',
    content => "Production puppetmaster is in control. Last run: ${timestamp}\n",
    }
}

But the resulting motd file has no date/time:

Production puppetmaster is in control. Last run:

What am I doing wrong?

Best Answer

I wouldn't use generate() at all, that is something to be avoided at all costs.

Instead, take a look at the stdlib Puppet module, and the following functions in particular:

strftime()
time()

Example: The following function call would result in a timestamp in the YYYY-MM-DD HH:MM:SS format:

$timestamp = stftime("%Y-%m-%d %k:%M:%S")