Problems adding attribute to XML node root via augeas

I use augeas to manage XML on some machines. While creating new nodes, as well as setting up many attributes worked like a charm, I bite my nails by adding a simple attribute to the XML file. XML is as follows:

<?xml version="1.0"?> <Context> <WatchedResource></WatchedResource> </Context> 

I'm just not trying to add allowLinking="true" to the root context of the node via

 set /files/path/to/my/file.xml/Context/#attribute/allowLinking "true" 

Unfortunately, always with a mistake

 /error = "put_failed" /error/path = "/files/path/to/my/file.xml/Context" /error/lens = "/usr/share/augeas/lenses/dist/xml.aug:134.10-.73:" /error/message = "Failed to match \n { /#attribute/ }?({ /#text/ … 

I am using puppet openource 3.4.2 with augeas 1.0.0.

Any suggestion what am I doing wrong?

+2
source share
1 answer

The order of questions in the Augeas tree. In this case, the XML node attributes must be set before the #text node and child nodes.

So you need to:

 ins #attribute before /files/test.xml/Context/#text set /files/test.xml/Context/#attribute/allowLinking true 

Note that this change is not idempotent since insert not an idempotent operation.

In Puppet, you can use onlyif to create this idempotent.

+3
source

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


All Articles