Ask Your Question

How to generate a time-stamp when an agent starts?

asked 2017-11-06 23:54:49 -0600

Peggory gravatar image

I want to generate a time stamp [notified to the client] and record it [in the puppet logs].

I've tried the following code (in a class file):

$timestamp = generate('/bin/date', '+%Y%d%m_%H:%M:%S')
notify { 'agent_running' :
    message => 'Agent started running at $time'}

When I apply and test the file:

Notice: Agent started running at $time
Notice: /Stage[main]/Run_message/Notify[agent_running]/message: defined 'message' as 'Agent started running at $time'

How can I pass the date command to a variable here?

edit retag flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted

answered 2017-11-07 02:16:31 -0600

stivesso gravatar image

updated 2017-11-07 02:18:46 -0600

Hi Peggory,

There's just a little mistake in your code. You are referring to $time instead of $timestamp (the one you defined) in your message. Besides that, you must use double quote for the interpolation.

The code below will work,

$timestamp = generate('/bin/date', '+%Y%d%m_%H:%M:%S')
notify { 'agent_running' :
    message => "Agent started running at ${timestamp}"}
edit flag offensive delete link more


Oops! Too many late night tabs open following different variations of solutions. Thanks so much for the help, and the explanation (still very new to puppet)

Peggory gravatar imagePeggory ( 2017-11-07 16:08:09 -0600 )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: 2017-11-06 23:54:49 -0600

Seen: 84 times

Last updated: Nov 07 '17