Puppet: System Administration Automated

Support

Ticket #1108 (closed defect: worksforme)

Opened 9 months ago

Last modified 8 months ago

variables become undefined on second puppetd run

Reported by: jeffl Assigned to: community
Priority: normal Milestone:
Component: library Version:
Severity: normal Keywords:
Cc: Triage Stage: Needs more info
Attached Patches: None Complexity: Unknown

Description

I have a minimally complex manifest that is exhibiting some strange behavior. Variables that are defined in the first run of puppetd become undefined during the second and subsequent runs.

A snippet of the module that causes the problem is (in the file modules/nfs/manifests/init.pp):

class nfs {
    service { 'nfs':
        ensure => running,
        enable => true,
        hasstatus => true,
        subscribe => [Package['net-fs/nfs-utils']],
        require => [Service['portmap']],
    }

    include nfs-utils
    include portmap
}

#class nfs::client inherits nfs {
#}

include client

If I uncomment the class nfs::client, and comment out the include client, the problem goes away. The content of client.pp is the uncommented nfs::client class shown above.

Attachments

ProblemPuppetManifest.tar.gz (5.9 kB) - added by jeffl on 02/28/08 22:50:00.

Change History

02/28/08 22:37:53 changed by luke

  • stage changed from Unreviewed to Needs more info.

I don't see any variables in this snippet, and I don't understand what the actual problem is. What problem goes away?

02/28/08 22:50:00 changed by jeffl

  • attachment ProblemPuppetManifest.tar.gz added.

02/28/08 22:51:02 changed by jeffl

I've attached the complete manifest that exhibits the problem.

On the second run, bind_server becomes undefined.

This is puppet-0.24.1

jeffl

04/08/08 18:05:46 changed by luke

I really need more information than this.

Your attached tarball is far too large for me to use it to attempt to reproduce the problem, and I only even see bind_server getting set to false, so I don't see how it's even used.

Can you be more explicit: How are the variables set, how are they unset, etc.? Is it multiple runs in a single puppetmasterd process (e.g., if you restart puppetmasterd, does the problem go away)? Multiple runs on the same puppetd process? Multiple runs regardless of process?

04/08/08 21:22:04 changed by jeffl

The gist of the problem is that global variables defined in modules/mod_name/manifests/init.pp are not made available to the puppetmaster the first time the file is parsed. It is available the next time the file is parsed.

So, if I have modules/ntp/manifests/init.pp:

$ntpserver = 'north-america.pool.ntp.org'

class ntp {
    file { '/etc/ntpd.conf':
        content => template('ntp/ntp.conf.erb'),
    }
}

The first time I run this class on any client the variable $ntpserver will be undefined. The very next time this class is used on any client, $ntpserver will be defined with the correct value.

04/08/08 21:42:03 changed by luke

  • status changed from new to closed.
  • resolution set to worksforme.

This is because the variable is defined outside of the class, and you're autoloading the file.

The first time through, the code that sets the variable is parsed too late to set the variable. The second time, the code is already loaded, so you get the value.

The fix is to move the setting into the class, or explicitly import this file.