所以我试图做一些与“Issues adding attribute to XML root node via augeas”问题看起来相同的事情,但是那里提供的答案对我不起作用。如果没有insert命令,我收到此错误消息(在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
这基本上就是我们在其他帖子中看到的内容。使用insert命令,这是我正在使用的相关代码:
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,然后当我尝试按照建议执行“插入”命令时,它也不起作用。
知道这里出了什么问题以及如何解决它?