Ask Your Question

Syntax error with "match" function

asked 2016-04-29 09:58:27 -0500

dannythk gravatar image

updated 2016-04-29 10:01:35 -0500

I am using Puppet 3.8.1, and we were not able to run the "match" function properly. The error message is: Error: Could not retrieve catalog from remote server: Error 400 on SERVER: Syntax error at '.'; expected '}' at .....

I even try the example it is listed on the web page / ruby library itself: "abc123".match(/([a-z]+)[1-9]+/)

edit retag flag offensive close merge delete


Are you putting that directly in your puppet code? Puppet is not ruby, and you would need to either make a function to apply the ruby for you, or put it in an inline_template call. - If you are trying to use it for matching a node name, the syntax is different

DarylW gravatar imageDarylW ( 2016-04-29 13:34:21 -0500 )edit

Daryl - Yes, I had it in the Puppet Code directly; will attempt to create a function in the future. For now, i found an alternative using "regsubst". I am trying to reduce number of hiera data by extracting the program name and version from a file name.

dannythk gravatar imagedannythk ( 2016-04-29 14:16:29 -0500 )edit

Glad you found a solution. That's the approach I would use. You also can use match variables in case statements.. Notice that the match variable is only in scope in the block following the match.

DarylW gravatar imageDarylW ( 2016-04-29 16:18:38 -0500 )edit

2 Answers

Sort by » oldest newest most voted

answered 2016-05-01 08:47:50 -0500

Henrik Lindberg gravatar image

The Puppet match function was introduced in Puppet 4.0.0. In earlier versions match using =~ and then access the numeric variables $0 - $n. (Or, depending on what is wanted, use the regsubst function).

edit flag offensive delete link more

answered 2016-05-02 18:49:30 -0500

WhatsARanjit gravatar image

Also, using the $var.function() notation is introduced in the "future" parser. If you're using 3.8.x, make sure you turn on the future parser. Otherwise, you must use the function($var) style notation.

edit flag offensive delete link more

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account.

Add Answer

Question Tools

1 follower


Asked: 2016-04-29 09:58:27 -0500

Seen: 379 times

Last updated: May 02 '16