Edit a XML configuration file with templates

40 views
Skip to first unread message

Edward

unread,
Apr 7, 2014, 6:24:15 PM4/7/14
to puppet...@googlegroups.com
Hello,

I am automating with Puppet the installation of a software on a Windows puppet agent. At a moment I need to edit a configuration file (xml file). I need to change the value of the "address" property in this bean:

    <bean id="IMFactory" class="org.apache.cxf.jaxws.JaxWsProxyFactoryBean">
        <property name="serviceClass" value="com.nano.imcommunication.IMWebServiceAPI" />
        <property name="address" value="http://10.126.81.152:8088/MockIM" />
    </bean>

I searched for documentation and found out that Augeas can only be used for Unix puppet agents.. I'm new to Puppet but I wonder if I can use templates to solve my problem, and if yes, how I have to do it.

Thanks by advance
Edward

jcbollinger

unread,
Apr 8, 2014, 12:26:10 PM4/8/14
to puppet...@googlegroups.com


On Monday, April 7, 2014 5:24:15 PM UTC-5, Edward wrote:
Hello,

I am automating with Puppet the installation of a software on a Windows puppet agent. At a moment I need to edit a configuration file (xml file).


No, in fact you need to ensure that a particular attribute of a particular element has the specified value.  You don't need or want to modify the file if it already is in the state you want.

 
I need to change the value of the "address" property in this bean:

    <bean id="IMFactory" class="org.apache.cxf.jaxws.JaxWsProxyFactoryBean">
        <property name="serviceClass" value="com.nano.imcommunication.IMWebServiceAPI" />
        <property name="address" value="http://10.126.81.152:8088/MockIM" />
    </bean>

I searched for documentation and found out that Augeas can only be used for Unix puppet agents.. I'm new to Puppet but I wonder if I can use templates to solve my problem, and if yes, how I have to do it.



You can manage the whole file via Puppet, using a template to generate the content, but templates are not a mechanism to "edit" a file.  That might look something like this:

modules/myapp/manifests/myapp/config.pp:
------
class myapp::config(
    $im_factory_address
  ) {
  file { '/path/to/myapp.conf.xml':
    ensure => 'file',
    content => template('myapp.conf.xml.erb'),
    # owner => 'WhoKnows',
    # group => 'WhoKnows',
    # mode => 0640,
  }
}


modules/myapp/templates/myapp.conf.xml.erb:
------
    <bean id="IMFactory" class="org.apache.cxf.jaxws.
JaxWsProxyFactoryBean">
        <property name="serviceClass" value="com.nano.imcommunication.IMWebServiceAPI" />
        <property name="address" value="<%= @im_factory_address %>" />
    </bean>


Of course, you also have to feed the desired value to your class, which should be arranged for by recording it in an hiera data file, and you have to declare that class for the target node(s).


John

Reply all
Reply to author
Forward
0 new messages