Hey littlechefs,
sometimes it is necessary to run commands before or after fixing a set of nodes, or a particular node. Let me give you a few examples:
* I would like to make sure that I have an up-to-date checkout of my kitchen before running fix
* After running fix I would like to run a testsuite on the new deployment, to make sure everything went smooth and fine.
* Before fixing a node I would like to remove the node from a loadbalancer, and add it again when deploying the node worked fine
* Schedule a downtime or send out a notification before fixing a node, or a set of nodes
Therefor I would be great if littlechef had a concept of pre- and post commit hooks. These hooks should be any executable scripts, such that they are completely decoupled from the python stack.
There should be global hooks which are executed very early/late in a fix run. Hooks for each node should be run around each deployment call.
Pre deploy hooks should take one or more arguments:
* one argument if it's not a global hook
* more than one argument if it is a global hook
Each argument should be the fqdn of the node which is about to be configured.
Post deploy hooks should take at least two arguments:
* the first is always the return code of either the fix command (if it is a global hook) or the deploy() method in case of an individual hook
* the next arguments are always the related node's fqdns
Hook scripts should always return with exit code 0 if everything worked fine, or >0 if sth. went wrong.
* If a global Pre deploy hook finish with an error, no nodes are deployed.
* If a node related pre deploy hook returns an error, deployment of this particular node is skipped
* the return code of the global post deploy hook is always the result of fix
* if a node specific post deploy hook indicates an error, fix will always return immediately, with an error.
The hooks which are run during a particular fix run should be configurable based on the chef_environment which is used, roles which are affected, etc.
I propose we add another directory to the kitchen which contain some kind of JSON hook definitions. Each definitions looks sth. like:
{
"name": "my pre deploy hook",
"type": "gobal_predeployhook",
"filters": {
"chef_environement": ["staging"],
},
"exec": "/usr/bin/somehook"
}
This means:
* Global pre commit hook
* only run if chef_environment is "staging" and "
a.google.de" or "
lb.google.de" are in the list of to-deployed nodes
* /usr/bin/somehook is executed
If "exec" does not start with a "/" the script is relative to the "hooks" dir in the kitchen.
This is just a summary of my initial idea. I'm very happy to discuss further details, esp. design related things ;)
If you guys like the idea, and we agree on some fundamentals I will open a wiki page for more detailed discussions.
Markus