How to revert a configuration with puppet
I wrote a module which writes a configuration for rsyslog in /etc/rsyslog.d/60-custconfig.conf using puppet.
When I add the module to the node, it works, but if I delete comment or delete the module call in the node, is it supposed to remove the file ? if not, is there a manner to rollback a configuration or installation ?
You don't revert actions Puppet has carried out by removing the resource. By removing the resource from your manifests, you're only telling Puppet not to manage it (anymore).
Also, Puppet simply doesn't remember/know about the previous states, so it can't revert to that. It just tries to change the system to a state you define in the manifests.
One way I see here, is to include the file
resource again, but now with ensure => absent
:
file {
'/etc/rsyslog.d/60-custconfig.conf':
ensure => absent,
}
Also you could change the design of the Puppet modules in this way:
- Manage all rsyslog configuration files in a rsyslog module.
- Create virtual custom defined types from other modules requiring the change in rsyslog.
- In the rsyslog module, collect the virtual configuration stanzas and instruct it to delete all undefined resources of that custom type.
Or even easier is to use the puppetlabs-concat module, define virtual concat::fragments in modules and collect them in the rsyslog module to build the '60-custconfig.conf' configuration file. If then the virtual resources get deleted from the other modules, the fragments gathered will result in a file without the fragments now unmanaged. Effectively, these will be deleted from the file.
You have to explicitly write code that will "undo" any specific actions that you want to revert.
For example, if you have a my_apache
module that install a few packages, configures several files, and ensures a certain state, you will have to write another class inside this module, lets call it my_apache::uninstall
, that undoes each of the things that your other module did. The undo class does not have to be inside, or part of the original module. It can be a completely separate class. A good way to change what classes are applied to a host, is to use an ENC.