使用puppet修改listener.ora
文件:
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"]
}
这不会导致任何傀儡错误,但会将新条目一直放在文件的末尾,而不是放在应该在的监听器块内。 (对我而言,这表明after
属性值与文件内容不匹配,因此puppet默认为追加模式。)
更改after
属性值以转义所有括号:
after => "^\s+\(ADDRESS = \(PROTOCOL = TCPS\)\(HOST = DB\)\(PORT = 1522\)\)",
在控制台中生成多个警告:
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
使其无法在卫星上使用。但是,执行完成后,新条目就位于应该存在的块内。
这提出了多个问题:
答案 0 :(得分:0)
是的,您确实需要在after
资源的file_line
属性中转义正则表达式的parantheses内部。在正则表达式中使用Parantheses来捕获表达式的一部分以供稍后变量使用。但是,由于您的正则表达式字符串有双引号("
),因此会出现警告。这导致Puppet解析器最初将\
解释为插值字符串转义而不是regexp转义。因此,您需要将正则表达式值更改为文字字符串,以便解析器正确解释它。
after => '^\s+\(ADDRESS = \(PROTOCOL = TCPS\)\(HOST = DB\)\(PORT = 1522\)\)',
这将删除您的Puppet警告。
以上解释也回答了您的另外两个问题,但这里有一个快速重复的摘要:
顺便说一句,puppet-lint也会为你抓住这个:https://github.com/rodjek/puppet-lint