-1

Using puppet to modify a listener.ora file:

file_line { 'addFloatingListenerTCPS':
  ensure  => present,
  path    => "${LSNR_PATH}/listener.ora",
  line    => "      (ADDRESS = (PROTOCOL = TCPS)(HOST = ${FLOATING_IP})(PORT = 1522))",
  after   => "^\s+(ADDRESS = (PROTOCOL = TCPS)(HOST = DB)(PORT = 1522))",
  require => Class["othernode"]
}

This doesn't cause any puppet errors, but places the new entry all the way at the end of the file, rather than inside the listener block where it should be. (To me this indicates that the after attribute value is not matching the file contents, thus puppet defaults to append mode).

Changing the after attribute value to escape all of the parenthesis:

after   => "^\s+\(ADDRESS = \(PROTOCOL = TCPS\)\(HOST =  DB\)\(PORT = 1522\)\)",

Generates multiple warnings in the console:

Warning: Unrecognised escape sequence '\(' in file /etc/puppet/modules/test_conf/manifests/init.pp at line 30
Warning: Unrecognised escape sequence '\(' in file /etc/puppet/modules/test_conf/manifests/init.pp at line 30
Warning: Unrecognised escape sequence '\)' in file /etc/puppet/modules/test_conf/manifests/init.pp at line 30
Warning: Unrecognised escape sequence '\(' in file /etc/puppet/modules/test_conf/manifests/init.pp at line 30
Warning: Unrecognised escape sequence '\)' in file /etc/puppet/modules/test_conf/manifests/init.pp at line 30
Warning: Unrecognised escape sequence '\(' in file /etc/puppet/modules/test_conf/manifests/init.pp at line 30
Warning: Unrecognised escape sequence '\)' in file /etc/puppet/modules/test_conf/manifests/init.pp at line 30
Warning: Unrecognised escape sequence '\)' in file /etc/puppet/modules/test_conf/manifests/init.pp at line 30

making it unusable in satellite. However, execution does complete and afterwards the new entry is inside the block where it should be.

This raises multiple questions:

  1. Are parenthesis interpreted as special chars, and if so why can't they be escaped?
  2. Do puppet stdlib regular expressions handle back references?
Matthew Schuchard
  • 25,172
  • 3
  • 47
  • 67
Derek_6424246
  • 237
  • 3
  • 12

1 Answers1

1

Yes, you do need to escape the parantheses insides of your regular expression within the after attribute of your file_line resource. Parantheses are used within regular expressions to capture parts of the expression for use by variables later. However, the warnings are arising because you have double quotes (") for your regexp string. This is causing the Puppet parser to initially interpret the \ as interpolated string escapes and not regexp escapes. Therefore, you need to change your regexp value to a literal string for the parser to interpret it correctly.

after   => '^\s+\(ADDRESS = \(PROTOCOL = TCPS\)\(HOST =  DB\)\(PORT = 1522\)\)',

This will remove your Puppet warnings.

The above explanation answers your two additional questions as well, but here is a quick repeated summary:

  1. Yes; they can and are.
  2. Yes

By the way, puppet-lint would have caught this for you also: https://github.com/rodjek/puppet-lint

Matthew Schuchard
  • 25,172
  • 3
  • 47
  • 67