puppet parameterised classes

I am having trouble getting parameterised classes working in puppet 2.6.4 (client and master)

######## from /etc/puppet/manifests/nodes.pp 
# defining one node to use certain version
#######################################################
node 'dev-internal-000008.domain.com' {
         include software($version="dev-2011.02.11")
}
# from /etc/puppet/modules/software/manifests/init.pp

I am setting the version here as the "default"

#
class software($version="dev-2011.02.04b") {
  File {
    links => follow
  }

  file { "/opt/software_AIR":
    ensure => directory
  }

  file { "/opt/software_AIR/share":
    source => "puppet://puppet/software/air/$version",
    recurse => "true",
  }
}
#

errors from puppet master

#
err: Could not parse for environment production: Syntax error at '='; expected ')' at /etc/puppet/manifests/nodes.pp:10 on node dev-internal-domain.com
#

found a fix for this

try

node 'dev-internal-000008.domain.com' {
  class { customsoftware:version => "dev-2011.02.04b" }
}

Solution 1:

Parameterized classes don't work with include, unfortunately. You have to use the new alternate class declaration syntax that was introduced at the same time as parameterized classes:

node 'dev-internal-000008.domain.com' {
    # include software($version="dev-2011.02.11") # (doesn't work)
    class {'software':
        version => "dev-2011.02.11",
    } # works
}

Things:

  • Note that it looks like a resource (file, service, etc.) declaration.
  • The fact that the definition and the declaration both start with the word class is confusing, but be careful and you'll be fine.
  • You can't declare a class this way more than once, the way you can with include. This is expected to change in 2.7, and some friendlier syntax will likely be introduced.