Question

I know I can sync directory in Puppet:

file { 'sqls-store':
    path    => '/some/dir/',
    ensure  => directory,
    source  => "puppet:///modules/m1/db-updates",
    recurse => true,
    purge => true
}

So when the new files are added they are copied to '/some/dir/'. However what I need is to perform some action for every new file. If I "Subscribe" to such resource, I don't get an array of new files. Currently I created external shell script which finds new files in that dir and executes action for each of them. Naturally, I would prefer not to depend on external script. Is there a way to do that with Puppet?

Thanks!

The use case for that is applying changes to DB schema that are being made from time to time and should be applied to all clients managed by puppet. In the end it's mysql [args] < update.sql for every such file.

Was it helpful?

Solution

Not sure I would recommend to have puppet applying the db changes for me.

For small db, it may work but for real world db... you want to be aware of when and how these kind of changes got applied (ordering of the changes, sometime require temp disk space adjustement, db downtime, taking backup before/after, reorg,...), most of the times your app should be adapted at the same time. You want more orchestration (and puppet isn't good at orchestration)

Why not using a tool dedicated to this task like

A poor men solution would be to use vcs-repo module and an exec to list modified files since last "apply".

OTHER TIPS

I agree with mestachs, puppet dealing with db updates it's not a great idea

You can try some kind of define:

define mydangerousdbupdate($name, $filename){
   file { "/some/dir/$filename":
    ensure  => present,
    source  => "puppet:///modules/m1/db-updates/$filename",
   }
   exec{"apply $name":
     command => "/usr/bin/mysql [args] < /some/dir/$filename > /some/dir/$filename.log",
     creates => "/some/dir/$filename.log"
   }
}

And then, you can instantiate with the different patches, in the preferred order

mydangerousdbupdate{"first_change":
   name => "first",
   filename => "first.sql",
}->mydangerousdbupdate{"second_change":
   name => "second",
   filename => "second.sql",
}
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top