Using augeas with a puppet to add an attribute to the root of a node

So, I'm trying to do something similar to the question about adding an attribute to the root of the XML node via augeas ", but the answer provided for me does not work. Without the insert command, I get this error message (in puppet agent -t --debug --verbose mode 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 

This is basically what we saw in this other post. Using the insert command, the appropriate code that I use is used here:

 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', ], } } 

Which gives me this error:

 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"] 

I tried using touch instead of insert based on " Link to doll template " for Augeas with this code:

 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', ], } } 

But then I get the error message:

 Error: /Stage[main]/mytomcat::Hardening::Context-xml/Augeas[context.xml]: Could not evaluate: Unknown command touch 

EDIT: I tried to make clear instead of touching, but this seems to be a NOOP command, and does not give me a different result than the first one shown at the very top of this entry.

So, I can’t execute touch using full XPath to try to set the attribute, it doesn’t work, because before #text node, clear you need to add #attribute node it appears NOOP, and then when I try to execute the β€œinsert” command, like recommended, it also does not work.

Any idea what is going wrong here and how can I fix it?

+6
source share

Source: https://habr.com/ru/post/985721/


All Articles