Ask Your Question
1

How can i replace a structure of a xml file and restart a service if neccessary

asked 2013-10-21 11:08:54 -0500

scoopex gravatar image

I would like to modify a xml structure like this:

<hudson>
  <disabledAdministrativeMonitors/>
  <version>1.534</version>
  <numExecutors>2</numExecutors>
  <mode>NORMAL</mode>
  <useSecurity>true</useSecurity>
  <authorizationStrategy class="hudson.security.GlobalMatrixAuthorizationStrategy">
   <permission>hudson.model.Hudson.Administer:foo-jenkins</permission>
   <permission>hudson.model.Hudson.Administer:foo-ma-admins</permission>
   <permission>hudson.model.Hudson.Read:anonymous</permission>
   <permission>hudson.model.Item.Read:anonymous</permission>
    <permission>hudson.model.View.Read:anonymous</permission>
</authorizationStrategy>

The other parts of the file are also modified by the jenkins application.

What i want to do:

  • Drop all permission-nodes
  • Add a defined set of permission-nodes
  • Restart the jenkins service if the resulting ...
(more)
edit retag flag offensive close merge delete

1 Answer

Sort by » oldest newest most voted
2

answered 2013-10-21 15:04:36 -0500

lavaman gravatar image

updated 2013-10-21 15:07:18 -0500

Augeas is the appropriate tool for this purpose. It exists to manage portions of formatted files while allowing content from other sources as well. However, the augeas resource type should be able to notify the service directly without the execs you have in there. You should probably looking at limiting the augeas commands to a certain subset of the file as described here:

http://projects.puppetlabs.com/projects/1/wiki/puppet_augeas#A+Better+Way

Also, style-wise, you should put the changes in a var and use that in the augeas resource:

$test_changes = [ 'array', 
                  'of', 
                  'augeas', 
                  'commands' ]

augeas { 'jenkins.config':
    incl ...
(more)
edit flag offensive delete link more

Comments

That´s correct, another resource triggered the restarts :-( Thank you.

scoopex gravatar imagescoopex ( 2013-10-21 15:42:56 -0500 )edit

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account.

Add Answer

Question Tools

1 follower

Stats

Asked: 2013-10-21 11:08:54 -0500

Seen: 638 times

Last updated: Oct 21 '13