Ask Your Question
0

Rebooting Systems with Puppet?

asked 2014-08-04 13:58:15 -0500

Red Cricket gravatar image

Hi,

I have a situation where I need to reboot a system after a particular puppet resource executes. I have this bit of puppet code to do the reboot:

class rebooter {
        if str2bool("$rebooted") {
                notify { 'its_been_rebooted': message => 'Its been rebooted!', }
        } else {
                notify { 'rebooting': message => 'rebooting!', }
                augeas{ 'set_reboot_fact_env_var' :
                        context => '/files/etc/security/pam_env.conf',
                        changes => ["set FACTER_rebooted DEFAULT='true'"],
                } 
#               -> exec { 'reboot': command => '/sbin/reboot', }
        }
}

As you can see I have commented out the reboot command so I can test. The idea I had was this. Test for a facter environment variable, FACTER_rebooted. If that fact is true then do whatever ... if that fact is not set edit the /etc/security/pam_env.conf so that FACTER_rebooted gets set to true and reboot the system.

When I test this module like so ...

#  puppet apply --modulepath=/etc/puppetlabs/puppet/modules -e "include rebooter"

... I get this output ...

Notice: Compiled catalog for dev-00 in environment production in 1.29 seconds
Notice: rebooting!
Notice: /Stage[main]/Rebooter/Notify[rebooting]/message: defined 'message' as 'rebooting!'
Notice: Finished catalog run in 10.98 seconds

... but there is no change to my /etc/security/pam_env.conf file.

edit retag flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted
3

answered 2014-08-04 15:25:46 -0500

ramindk gravatar image

You might try using refreshonly so the Exec will only run if it's been notified.

class rebooter {
  if str2bool("$rebooted") {
    notify { 'its_been_rebooted': message => 'Its been rebooted!', }
  } else {
    notify { 'rebooting': message => 'rebooting!', }
    augeas{ 'set_reboot_fact_env_var' :
      context => '/files/etc/security/pam_env.conf',
      changes => ["set FACTER_rebooted DEFAULT='true'"],
      notify  => Exec['reboot'],
  } 

  exec { 'reboot':
    command     => '/sbin/reboot',
    refreshonly => true,
  }
}
edit flag offensive delete link more

Comments

Looks like augeas doesn't support the `/etc/security/pam_env.conf` file.

Red Cricket gravatar imageRed Cricket ( 2014-08-04 15:42:32 -0500 )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

2 followers

Stats

Asked: 2014-08-04 13:58:15 -0500

Seen: 1,298 times

Last updated: Aug 04 '14