How to ensure a variable gets set, before a File or Service gets set.

40 views
Skip to first unread message

Grant Schoep

unread,
Oct 7, 2014, 10:20:41 AM10/7/14
to puppet...@googlegroups.com
So I have the following puppet rule. Pasted below. The problem is, sometimes, I see it looks like it is running the File before it sets the variable $sendmail_file in the case statement above. The reason I believe this, is because of the error message that it reports. Which is

Error Message:
err: /File[sendmailcf]/ensure: change from absent to file failed: Could not set 'file on ensure: No such file or directory - /etc/mail/sendmail.cf.puppettmp_6850 at /etc/puppet/modules/sendmail/manifests/client.pp:40

What I can't figure out, is how to ensure that that variable gets set, before it gets used. Any pointers?

My puppet rule.
class sendmail::client {
  case $::operatingsystem {
    /^(RedHat|CentOS)/: {
      case $::lsbmajdistrelease  {
        '5': {
             $sendmail_file = 'sendmail.cf.rhel5'
        }
        '6': {
             $sendmail_file = 'sendmail.cf.rhel6'
        }
        default: {
          fail("Unsupported OS Major version ${::operatingsystem} ${::lsbmajdistrelease}")
        }
      }
    }
    default: {
      fail("Unsupported operating system: ${::operatingsystem}")
    }
  }

  service { sendmail:
    name   => sendmail,
    enable => true,
    ensure => running,
  }

  file { sendmailcf:
    path => "/etc/mail/sendmail.cf",
    mode => 644,
    owner => root,
    group => root,
    ensure => present,
    source => "puppet:///modules/sendmail/$sendmail_file",
    notify => Service[sendmail],
  }
}


jcbollinger

unread,
Oct 8, 2014, 9:20:52 AM10/8/14
to puppet...@googlegroups.com


On Tuesday, October 7, 2014 9:20:41 AM UTC-5, Grant Schoep wrote:
So I have the following puppet rule. Pasted below. The problem is, sometimes, I see it looks like it is running the File before it sets the variable $sendmail_file in the case statement above. The reason I believe this, is because of the error message that it reports. Which is

Error Message:
err: /File[sendmailcf]/ensure: change from absent to file failed: Could not set 'file on ensure: No such file or directory - /etc/mail/sendmail.cf.puppettmp_6850 at /etc/puppet/modules/sendmail/manifests/client.pp:40

What I can't figure out, is how to ensure that that variable gets set, before it gets used. Any pointers?


Puppet evaluates the class body in order, left-to-right, top-to-bottom, so I think your hypothesis is mistaken.  Moreover, your error message does not seem to agree with your hypothesis: it is about a local file on the node, whereas the only variable in your class controls which 'source' file to use on the master.  (The same principle is in operation even if you're running in masterless mode.)

It looks like Puppet wants to update your sendmail.cf.  In standard fashion, it tries to create the new version as a temp file first, which (if all goes well) it will later move to replace the original file.  It is unable to create the temp file, however, or else something prevents access to it or removes it again immediately after it is created.  Perhaps your disk is full, but more likely some form of access control is getting in Puppet's way.


John

Grant Schoep

unread,
Oct 9, 2014, 9:51:54 AM10/9/14
to puppet...@googlegroups.com

Ah, you are right, I was thinking "too complicated"  The dependency I was missing was the sendmail package, which created the /etc/mail/ directory.   I was thrown off by the "puppettmp_6850" name, thinking that was "junk" from an uninitialized variable.


Reply all
Reply to author
Forward
0 new messages