NUB here with a question as I go through the tutorials

20 views
Skip to first unread message

Erik Ritzman

unread,
Oct 29, 2014, 1:09:32 PM10/29/14
to puppet...@googlegroups.com
I am fairly new to DSP and am experimenting as I follow along with the Puppet Tutorial

Playing off of the Task 1 in the Conditionals section...
 my conditionals.pp worked as the example gave; however I was wanting to add on the "else" statement what the "uptime" is and then to state when the device was last rebooted.

if $::uptime_hours < 2 {
  $myuptime = "Uptime is less than two hours. \n"
}

  elsif $::uptime_hours < 5 {
    $myuptime = "Uptime is less than five hours. \n"
  }

  else {
$reboot_time = "${who -b}"
    $myuptime = "Uptime is greater than 4 hours. \n
    Your uptime is $uptime.\n
Your last reboot was $reboot_time."
  }

  file {'/root/conditionals.txt':
    ensure  => present,
    content => $myuptime,
    }

My output ends up being 

 
Uptime is greater than 4 hours. 

    Your uptime is 4 days.

Your last reboot was { -b}.


Again, I'm just learning here ...

how would I go about adding the "bash command to pull the "who -b" and echoing it to the appropriate spot?


Walid

unread,
Oct 29, 2014, 1:23:06 PM10/29/14
to puppet...@googlegroups.com
you would need the exec resource to execute the "who -b" and filters you apply to it 

--
You received this message because you are subscribed to the Google Groups "Puppet Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to puppet-users...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/puppet-users/0f583245-d8cb-49ed-8f24-380c169bf4dd%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Felix Frank

unread,
Nov 9, 2014, 7:03:55 PM11/9/14
to puppet...@googlegroups.com
Ah, but that won't solve the stated problem.

The $uptime can be used in some Puppet output because it is available as a fact value. To make similar use of the last reboot time, you would need to create a custom fact that will make this value available.

To use shell code for this, use external facts.

modules/site/facts.d/last_reboot:
#!/bin/sh
echo last_reboot=`who -b`

The manifest can use this value as $last_reboot then.

HTH,
Felix


On 10/29/2014 06:22 PM, Walid wrote:
Reply all
Reply to author
Forward
0 new messages