Puppet class with parameter

0

I am trying to get a puppet class with parameters, Here is what I've tried

class testing ( String $file = 'testing' ) {
        file { "/tmp/$file":
          ensure => present,
          mode => 0777,
          content => "Testing123"
        }
}

When I run this I get the error:

Could not parse for environment production: Syntax error at 'String'; expected ')'

Tim Holum

Posted 2015-11-22T22:52:51.333

Reputation: 163

Not an expert here, but looking at the puppet documentation and the error message, maybe you need to remove the space character between the open bracket and "String". Thats the only syntactical difference I can see between that and the Puppetlabs documentation example. – davidgo – 2015-11-23T00:17:55.293

What version of puppet are you using? – daxlerod – 2015-11-23T14:33:22.077

Answers

2

It sounds like you are using a version of puppet older than 4.0, and not using the 'future' parser. Data types were added with the new version of the puppet language.

You have 3 options:

  1. Remove String. Even in configurations where declaring a data type is allowed, it's optional. Inside your class, you can use a function to validate that the parameter is a string.
  2. Enable the future parser. This is done in your puppet config file, and you may find that your other code is not compatible.
  3. Upgrade to a 4.x version of puppet. This may also result in incompatibilities with the rest of your environment.

If it were me, I'd do #1.

daxlerod

Posted 2015-11-22T22:52:51.333

Reputation: 2 575