Bug #11133

Regex captures don't work in node definitions

Added by Neil Hemingway 6 months ago. Updated 2 months ago.

Status:Duplicate Start date:12/02/2011
Priority:Normal Due date:
Assignee:Neil Hemingway % Done:

0%

Category:node
Target version:-
Affected Puppet version:2.7.1 Branch:
Keywords:node regex capture
Votes: 0

Description

With the following manifest:

node /^ws-([[:digit:]]+)/ {
  $hostid = $2
  notice("site.pp: Hostid: $hostid")

  # Same regex as above
  if $hostname =~ /^ws-([[:digit:]]+)/ {
    notice("\$2: $2")
  }
}

When run against a machine ws-01, I get out:

puppet-master[29847]: (Scope(Node[ws-:digit:])) site.pp: Hostid: 
puppet-master[29847]: (Scope(Node[ws-:digit:])) $2: 01

Related issues

duplicates Puppet - Feature #2628: It would be useful if node name regexps set $1 Accepted 09/11/2009

History

Updated by Neil Hemingway 6 months ago

Grr. horrible wiki formatting there. Try again…

node /^ws-([[:digit:]]+)/ {
  $hostid = $2
  notice("site.pp: Hostid: $hostid")

  # Same regex as above
  if $hostname =~ /^ws-([[:digit:]]+)/ {
    notice("\$2: $2")
  }
}

When run against a machine ws-01, I get out:

puppet-master[29847]: (Scope(Node[ws-:digit:])) site.pp: Hostid: 
puppet-master[29847]: (Scope(Node[ws-:digit:])) $2: 01

I’m working on a patch

Updated by Neil Hemingway 6 months ago

patch.

Note: No tests because (as the commit makes clear) I’m uncertain whether this is the best place for the fix. I need a better understanding of the architecture of puppet.

Updated by Josh Cooper 5 months ago

  • Description updated (diff)

Updated by Josh Cooper 5 months ago

  • Status changed from Unreviewed to Duplicate

Updated by Daniel Pittman 2 months ago

  • Target version deleted (2.7.x)

Also available in: Atom PDF