In puppet, modules can have a dash in their name, and thus variables can, too. But then, how can we use such variables?

For example, I have a $ssh_mode variable defined in a google-authenticator::params class, so I expect to be able to call $google-authenticator::params::ssh_mode, but puppet (0.25.5) cuts on the dash. Using ${google-authenticator::params::ssh_mode} doesn't help either.

What can I do to access this variable?

  • I don't suppose the clean and obvious "don't use dashes in your module names" is going to cut it? – womble Apr 20 '12 at 5:55
  • Well, that's what I was wondering. According to @m0dlx's answer, I will have to do this. – ℝaphink Apr 20 '12 at 6:01

You could find this works in later versions. Certainly in Puppet 2.7, the variable interpolation in strings now includes dashes (which also causes a few compatibility issues).

The deeper problem though is you're relying on undefined handling of modules with dashes in. I'd strongly suggest you rename the module to use an underscore, or no separator. There are many bugs in Puppet (that come and go between different major versions) if you don't stick to this recommendation:

Class names, module names, and the names of defined and custom resource types should be restricted to lowercase alphanumeric characters and underscores, and should begin with a lowercase letter; that is, they should match the expression [a-z][a-z0-9_]*. Although some names that violate these restrictions currently work, using them is not recommended.

From Language Guide (Reserved Words & Acceptable Characters).


Here is a page describing the allowed characters in puppet identifiers.

Under class names section, you can read:

 …but if you use any hyphens, you screw up qualified variable access.

Under variables section, you can read:

* [a-zA-Z0-9_]+ (No unicode nonsense or %@^ etc.)
* i.e. no hyphens, ever.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.