Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
274 views
in Technique[技术] by (71.8m points)

puppet - Issues adding attribute to XML root node via augeas

I am using augeas to manipulate XML on some machines. Whereas creating new nodes and also setting a bunch of attributes worked like a charm I'm biting my nails of adding a simple attribute to an XML file. XML looks like the following:

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

I'm no just trying to add allowLinking="true" to the Context root node via

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

Which is unfortunately always failing with

/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 
    { /#attribute/ }?({ /#text/ …

I'm using puppet opensource 3.4.2 with augeas 1.0.0.

Any suggestion what I'm doing wrong?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

Order matters in the Augeas tree. In that case, XML node attributes need to be set before the #text node and the child nodes.

So what you need is:

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 is not an idempotent operation.

On Puppet, you could use onlyif to make this idempotent.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...