因此,我正在尝试做一些看起来与“通过 augeas 向 XML 根节点添加属性的问题”中的问题相同的事情,但是那里提供的答案对我不起作用。如果没有插入命令,我会收到此错误消息(在puppet agent -t --debug --verbose
模式下):
Debug: Augeas[context.xml](provider=augeas): /augeas/files/usr/share/tomcat/conf/context.xml/error/message = Failed to match
{ /#attribute/ }?({ /#text/ = /(\\]\\]\\]*[^]\001-\004<>][^]\001-\004<]*\\]|(\\][^]\001-\004<]|[^]\001-\004<][^]\001-\004<])[^]\001-\004<]*\\]|[^]\001-\004<]\\])(\\]\\]*[^]\001-\004<>][^]\001-\004<]*\\]|[^]\001-\004<][^]\001-\004<]*\\])*(\\]\\]*([^]\001-\004<>][^]\001-\004<]*|)|[^]\001-\004<][^]\001-\004<]*|)|\\]\\]\\]*([^]\001-\004<>][^]\001-\004<]*|)|(\\][^]\001-\004<]|[^]\001-\004<][^]\001-\004<])[^]\001-\004<]*|\\]|[^]\001-\004<]/ } | { /#comment/ = /([^\001-\004-]|-[^\001-\004-])*/ } | <<rec>> | { /[:A-Z_a-z][.0-:A-Z_a-z-]*/ = /#empty/ } | { /#pi/ })*
with tree
{ "#text" = "
" } { "#comment" = " Default set of monitored resources " } { "#text" = "
" } { "WatchedResource" } { "#text" = "
" } { "#comment" = " Uncomment this to disable session persistence across Tomcat restarts " } { "#text" = "
" } { "#comment" = "
<Manager pathname="" />
" } { "#text" = "
" } { "#comment" = " Uncomment this to enable Comet connection tacking (provides events
on session expiration as well as webapp lifecycle) " } { "#text" = "
" } { "#comment" = "
<Valve className="org.apache.catalina.valves.CometConnectionManagerValve" />
" } { "#text" = "
" } { "Manager" } { "#attribute" }
Debug: Augeas[context.xml](provider=augeas): Closed the augeas connection
Error: /Stage[main]/mytomcat::Hardening::Context-xml/Augeas[context.xml]: Could not evaluate: Saving failed, see debug
这基本上就是我们在另一篇文章中看到的。使用插入命令,这是我正在使用的相关代码:
class mytomcat::hardening::context-xml {
require ::augeas
augeas{ 'context.xml':
lens => 'Xml.lns',
incl => '/usr/share/tomcat/conf/context.xml',
changes => [
'ins #attribute before Context/#text',
'set Context/#attribute/allowLinking false',
],
}
}
这给了我这个错误:
Debug: Augeas[context.xml](provider=augeas): sending command 'ins' with params ["#attribute", "before", "/files/usr/share/tomcat/conf/context.xml/Context/#text"]
Debug: Augeas[context.xml](provider=augeas): Closed the augeas connection
Error: /Stage[main]/mytomcat::Hardening::Context-xml/Augeas[context.xml]: Could not evaluate: Error sending command 'ins' with params ["#attribute", "before", "/files/usr/share/tomcat/conf/context.xml/Context/#text"]/Error sending command 'ins' with params ["#attribute", "before", "/files/usr/share/tomcat/conf/context.xml/Context/#text"]
我尝试使用touch
而不是insert
,基于Augeas的“ Puppet Type Reference ”页面,使用以下代码:
class mytomcat::hardening::context-xml {
require ::augeas
augeas{ 'context.xml':
lens => 'Xml.lns',
incl => '/usr/share/tomcat/conf/context.xml',
changes => [
'touch Context/#attribute',
'touch Context/#attribute/allowLinking',
'set Context/#attribute/allowLinking false',
],
}
}
但后来我收到错误消息:
Error: /Stage[main]/mytomcat::Hardening::Context-xml/Augeas[context.xml]: Could not evaluate: Unknown command touch
编辑:我尝试做一个clear
而不是触摸,但这似乎是一个 NOOP 命令,并没有给我一个与本文最顶部显示的第一个不同的结果。
所以,我做不到touch
,使用完整的 XPath 尝试设置属性不起作用,因为您必须在 #text 节点之前添加 #attribute 节点,这clear
似乎是 NOOP,然后当我尝试做推荐的“插入”命令也不起作用。
知道这里出了什么问题以及如何解决吗?