使用augeas with puppet将属性添加到根节点

Bra*_*les 6 xml puppet augeas

所以我正在尝试做一些看起来与" 通过augeas向XML根节点添加属性的问题"相同的问题,但是提供的答案对我不起作用.没有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
Run Code Online (Sandbox Code Playgroud)

这基本上就是我们在其他帖子中看到的内容.使用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', 
    ],
  }
}
Run Code Online (Sandbox Code Playgroud)

这给了我这个错误:

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"]
Run Code Online (Sandbox Code Playgroud)

我尝试使用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', 
    ],
  }
}
Run Code Online (Sandbox Code Playgroud)

但后来我收到错误信息:

Error: /Stage[main]/mytomcat::Hardening::Context-xml/Augeas[context.xml]: Could not evaluate: Unknown command touch
Run Code Online (Sandbox Code Playgroud)

编辑:我尝试做一个clear而不是触摸,但这似乎是一个NOOP命令,并没有给我一个不同于本文最顶部显示的第一个结果.

所以,我做不到touch,使用完整的XPath尝试设置属性不起作用,因为你必须在#text节点之前添加#attribute节点,clear看起来是一个NOOP,然后当我尝试做推荐的"插入"命令也不起作用.

知道这里出了什么问题以及如何解决它?