0

If I have a configuration in Puppet which changes between two runs, it is possible to implement some migration tasks for this?

For example, I specify

apache::vhost { 'vhost.example.com':
  port    => '80',
  docroot => '/var/www/vhost',
}

in the beginning, and happily work with this for some months. Then I want to change the docroot to /home/www/vhost. Puppet then changes the apache vhost, but I also have some data in the old /var/www/vhost folder which is not managed by Puppet. Is it possible put some migration steps in between, for example:

"If the docroot changes from /var/www/vhost to /home/www/vhost then: mv /var/www/vhost /home/www/vhost".

Thanks!

Hellstorm
  • 145
  • 6

1 Answers1

0

Probably using complicated tricks you can, but I wont do it that way.

The difficulty comes from the fact that puppet's language is not imperative, it's declarative so when you change your variable setting you don't have the previous value. Puppet just checks if the machine is in the state you want and if not makes sure it becomes as you asked or errors out.

IMHO the correct way to do this kind of changes is to provision the new site like you did with the old one assuming you did it with puppet, and check for the existence of the old document root, if you find it you delete it.

Here's an (untested) example of your code after you decided to change docroot:

$old_docroot = "/var/www/vhost"
$new_docroot = "/home/www/vhost"

apache::vhost { 'vhost.example.com':
  port    => '80',
  docroot => $new_docroot,
  notify  => Exec['cleanup_old_docroot_if_needed'],
}

exec {'cleanup_old_docroot_if_needed':
  command     => "/bin/rm -qrf $old_docroot",
  refreshonly => true,
}
Fredi
  • 2,257
  • 10
  • 13