Re: [Puppet Users] How manage xml elements as resources?

2013-01-08 Thread j4m3s
I started to look into this for JBoss - it uses an xml config file but the 
app itself makes changes to the file
when you deploy an application (in domain mode) - so using the normal file 
resource in puppet simply wouldn't work.

I found the Augeas documentation to be rather hard to get into (or even 
find).  I was expecting there to be
a straightforward (xpath-style?) lens for editing xml files but couldn't 
find anything.  There wasn't a JBoss AS lens
either, which again was surprising since JBoss is a RedHat product and it 
looks like Augeas is sponsored by RedHat.

In the end I found a workaround for JBoss so I can just use normal puppet 
File type, though my XPath thoughts
did make me wonder whether I ought to actually be looking for an xpath 
type/ resource/ plugin for puppet (sorry
for the incorrect terminology).  Augeas actually uses a syntax that looks a 
lot like xpath...

On Monday, January 7, 2013 11:34:16 PM UTC, Roman Shaposhnik wrote:

 On Mon, Jan 7, 2013 at 1:24 PM, Schofield dbsch...@gmail.comjavascript: 
 wrote: 
  I would like to use puppet classes to inject and/or replace xml elements 
  into an existing xml configuration file.  This seems to me to be a 
 common 
  problem already solved.  Can anyone suggest the easiest way to do this? 

 Well, the tool du jour for that would be augeas. That said, if the config 
 file actually happens to be under your manifest control fully (even though 
 different resources are depositing bits and pieces of configuration info 
 into it) you could go with virtual resource template and sed. 

 Thanks, 
 Roman. 


-- 
You received this message because you are subscribed to the Google Groups 
Puppet Users group.
To view this discussion on the web visit 
https://groups.google.com/d/msg/puppet-users/-/x_JMrlOwZNIJ.
To post to this group, send email to puppet-users@googlegroups.com.
To unsubscribe from this group, send email to 
puppet-users+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/puppet-users?hl=en.



Re: [Puppet Users] How manage xml elements as resources?

2013-01-08 Thread Dominic Cleal
On 08/01/13 11:01, j4m3s wrote:
 I started to look into this for JBoss - it uses an xml config file but
 the app itself makes changes to the file
 when you deploy an application (in domain mode) - so using the normal
 file resource in puppet simply wouldn't work.
 
 I found the Augeas documentation to be rather hard to get into (or even
 find).  I was expecting there to be
 a straightforward (xpath-style?) lens for editing xml files but couldn't
 find anything.  There wasn't a JBoss AS lens
 either, which again was surprising since JBoss is a RedHat product and
 it looks like Augeas is sponsored by RedHat.

If it's just XML, there's a lens for that already - it wouldn't need
another.  XML support is limited before Augeas 1.0 (released last month)
as it only supports double quotes.

Docs are a problem, but that's because it's primarily a library and so
docs are targeted at those developers.  The Augeas type in Puppet is
very low-level, so it's tricky to use.  Most docs about it are here. but
there's no XML example yet:

http://projects.puppetlabs.com/projects/puppet/wiki/Puppet_Augeas

 In the end I found a workaround for JBoss so I can just use normal
 puppet File type, though my XPath thoughts
 did make me wonder whether I ought to actually be looking for an xpath
 type/ resource/ plugin for puppet (sorry
 for the incorrect terminology).  Augeas actually uses a syntax that
 looks a lot like xpath...

Indeed, it's inspired by XPath.  I tend to start with augtool to see how
the tree looks on the original file and the finished file, then it's
much easier to create expressions to make the changes:

$ augtool --noautoload -r .
augtool set /augeas/load/Xml/lens Xml.lns
augtool set /augeas/load/Xml/incl /jbossas.xml
augtool load
augtool print /files/jbossas.xml/
/files/jbossas.xml
/files/jbossas.xml/host
/files/jbossas.xml/host/#text[1] = \n  
etc.

The commands available in Puppet mirror those in the augtool (a test
utility).

I came up with this example to apply the transformation you mentioned:

augeas { jbossas-datasource:
  lens= Xml.lns,
  incl= /etc/jbossas.xml,
  changes = [
set host/server[#attribute/name='one'] '',
set host/server[#attribute/name='one']/datasource #empty,
set
host/server[#attribute/name='one']/datasource/#attribute[name='example']/name
example,
  ],
}

Cheers,

-- 
Dominic Cleal
Red Hat Engineering

-- 
You received this message because you are subscribed to the Google Groups 
Puppet Users group.
To post to this group, send email to puppet-users@googlegroups.com.
To unsubscribe from this group, send email to 
puppet-users+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/puppet-users?hl=en.



[Puppet Users] How manage xml elements as resources?

2013-01-07 Thread Schofield
I would like to use puppet classes to inject and/or replace xml elements 
into an existing xml configuration file.  This seems to me to be a common 
problem already solved.  Can anyone suggest the easiest way to do this?
 
An example use case would look like something like this.
Given xml file:
 
host
  server name=one/
  server name=two/
/host
 
I want to inject datasource name=example/ into server one resulting in.
 
 host
  server name=one
datasource name=example/
  /server
  server name=two/
/host
 
Of course puppet would still need to make sure datasource example is always 
under server one should someone manually modify the server one element in 
the future.

-- 
You received this message because you are subscribed to the Google Groups 
Puppet Users group.
To view this discussion on the web visit 
https://groups.google.com/d/msg/puppet-users/-/O61X63H4TAEJ.
To post to this group, send email to puppet-users@googlegroups.com.
To unsubscribe from this group, send email to 
puppet-users+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/puppet-users?hl=en.



Re: [Puppet Users] How manage xml elements as resources?

2013-01-07 Thread Roman Shaposhnik
On Mon, Jan 7, 2013 at 1:24 PM, Schofield dbschofi...@gmail.com wrote:
 I would like to use puppet classes to inject and/or replace xml elements
 into an existing xml configuration file.  This seems to me to be a common
 problem already solved.  Can anyone suggest the easiest way to do this?

Well, the tool du jour for that would be augeas. That said, if the config
file actually happens to be under your manifest control fully (even though
different resources are depositing bits and pieces of configuration info
into it) you could go with virtual resource template and sed.

Thanks,
Roman.

-- 
You received this message because you are subscribed to the Google Groups 
Puppet Users group.
To post to this group, send email to puppet-users@googlegroups.com.
To unsubscribe from this group, send email to 
puppet-users+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/puppet-users?hl=en.