Search code examples
jenkinspuppetrhel

puppet detect if a file changed but don't change it


I want to manage the config.xml file of the jenkins-service with puppet. The problem is that if Puppet changes the config.xml file and than restarts the jenkins service, the config.xml file gets overwritten by the currently loaded configuration of jenkins and the changes made by puppet are lost.

That's what i have now:

file { '/var/lib/jenkins/config.xml':
  source    => 'puppet:///modules/jenkins/config.xml',
  owner     => jenkins,
  group     => jenkins,
  mode      => '0644'
}

service { 'jenkins':
  ensure    => running,
  enable    => true,
  subscribe => File['/var/lib/jenkins/config.xml']
}

My approach is to stop the jenkins service, than copy the config.xml and start the service again... naturally the service should not be stopped and started again every time puppet runs but only if the config.xml changed. I don't know how to do this with puppet and even if it is possible. Any ideas?

Any help would be much appreciated


Solution

  • This is sort of a painful thing to handle with puppet, but one way to do it is to detect the change to a staging file and then use an exec to sequence the file changes:

    file { '/some/staging/path/config.xml':
      source    => 'puppet:///modules/jenkins/config.xml',
      owner     => jenkins,
      group     => jenkins,
      mode      => '0644',
      notify => Exec['Update Jenkins Config']
    }
    
    exec { 'Update Jenkins Config':
      command     => '/sbin/service jenkins stop && /bin/cp /some/staging/path/config.xml /var/lib/jenkins/config.xml && /sbin/service jenkins start',
      refreshonly => true
    }