0

I would like to iterate all the child elements in the XML.

Is it possible to iterate dynamically ? In other words, I would like to check / edit all the nested elements without knowing the last element number.

For eg:

In the following "server-groups" element contains three server-group child element. I would like to iterate all the server-group element without knowing the counts. Right now It is three. So that I could access the last element. If I dont know the last element number, Is it possible to iterate ?

<server-groups>
    <server-group name="ServiceGroupOne" profile="full-ha">
        <system-properties>
            <property name="jboss.default.multicast.address" value="232.0.2.20" boot-time="true"/>
            <property name="modcluster.proxylist" value="192.168.79.77:7777" boot-time="true"/>
            <property name="modcluster.lbgroup" value="SearchGroupOne" boot-time="true"/>
        </system-properties>
    </server-group>
    <server-group name="ServiceGroupTwo" profile="full-ha">
        <system-properties>
            <property name="jboss.default.multicast.address" value="232.0.2.20" boot-time="true"/>
            <property name="modcluster.lbgroup" value="SearchGroupTwo" boot-time="true"/>
            <property name="modcluster.proxylist" value="192.168.79.77:7777" boot-time="true"/>
        </system-properties>
    </server-group>
    <server-group name="ServiceGroupThree" profile="full-ha">
        <system-properties>
            <property name="modcluster.lbgroup" value="CommonSearchGroup" boot-time="true"/>
            <property name="modcluster.proxylist" value="192.168.79.77:7777" boot-time="true"/>
            <property name="jboss.default.multicast.address" value="232.0.2.20" boot-time="true"/>
        </system-properties>
   </server-group>
</server-groups>
ArunRaj
  • 1,780
  • 2
  • 26
  • 48

1 Answers1

1

In Augeas, iterating can be done using setm:

  COMMAND
    setm - set the value of multiple nodes

  SYNOPSIS
    setm <BASE> <SUB> [<VALUE>]

  DESCRIPTION
    Set multiple nodes in one operation.  Find or create a node matching SUB
    by interpreting SUB as a  path expression relative to each node matching
    BASE. If SUB is '.', the nodes matching BASE will be modified.

  OPTIONS
     <BASE>    the base node
     <SUB>     the subtree relative to the base
     <VALUE>   the value for the nodes
raphink
  • 3,625
  • 1
  • 28
  • 39
  • @Raphink : Wow. Itz cool. But Having one more challenge in this tool. If you look my example, "modcluster.proxylist" key is placed in different positions. Is it possible to change the value of the property at one short ? If Possible, Could you please explain me ? – ArunRaj Nov 11 '15 at 12:16
  • 1
    Since you've opened a [new question](http://stackoverflow.com/questions/33664488/how-to-use-setm-in-puppet/33666228#33666228) for that, I've answered it there ;-) – raphink Nov 12 '15 at 07:27