Project

General

Profile

Scripted Processes » History » Version 1

Ashley Penney, 09/12/2011 10:33 AM

1 1 Ashley Penney
h2. Scripted processes
2
3
An area that Puppet/foreman currently is weak in, and can't really handle, is in creating, launching, and monitoring scripts and one-time run Puppet manifests for various deployment style tasks.  I propose that we extend and improve Foreman to fill this gap by effectively copying the functionality of Controltier (www.controltier.org) and Rundeck (www.rundeck.org) but significantly improving upon both tools by significantly leveraging the power of Puppet/foreman to significantly improve the user experience and tighten the integration between the two problem splaces.
4
5
h2. Process
6
7
At the heart of this enhancement is the ability to create processes that carry out sequential steps in order to perform an operations task.  The example of this that I will use throughout this process is an existing script of mine (modified to hide details) within Rundeck:
8
<pre>
9
function dependencies () { 
10
sudo yum install -y svn php make 
11
} 
12
13
function build () { 
14
sudo rm -r @option.location@/* 
15
sudo rm -r /tmp/build 
16
mkdir /tmp/build ; cd /tmp/build 
17
svn checkout https://SVN/ --username apenney --password fake --non-interactive 
18
cd /tmp/build/SVN/src/ 
19
make 
20
cp -R a b c d /tmp/build/SVN/build/htdocs 
21
sudo cp -R /tmp/build/SVN/build/htdocs/* @option.location@ 
22
} 
23
24
function cleanup () { 
25
rm -rf /tmp/build 
26
} 
27
28
dependencies 
29
build 
30
cleanup
31
</pre>
32
33
<pre>
34
sudo rm /tmp/ui-config.pp 
35
36
cat > /tmp/ui-config.pp <<EOF 
37
file { "/var/www/html/server/smsconfig.inc": 
38
ensure => present, 
39
source => "puppet://puppet/modules/project/var/www/html/server/@option.role@/smsconfig.inc", 
40
} 
41
EOF 
42
43
sudo -s puppet apply --modulepath=/etc/puppet/modules/@option.role@/ /tmp/ui-config.pp 
44
sudo rm /tmp/ui-config.pp
45
</pre>
46
47
As you can see from the two scripts this checks code out of SVN and builds it correctly then moves it into place. &nbsp;The next step does a one-time checkout of the configuration files (there are others in the original script) and then leaves the application unmanaged by Puppet so that developers can work from there. &nbsp;While this might not be the best example (as it could be modelled in Puppet) you can imagine more&nbsp;sophisticated&nbsp;examples.
48
49
h3. Creating new processes
50
51
For this functionality I would like a&nbsp;separate&nbsp;configuration called Processes and under here I could define a process. &nbsp;A process is defined as a sequence of steps and these can be either new steps or references to existing steps. &nbsp;Once you choose to add a new step you are&nbsp;&nbsp;directed to choose between two options (to begin) called Puppet process and Script process. &nbsp;If you choose Puppet process you are given a space in which to write a Puppet manifest which will only be applied when manually called by a process. &nbsp;This keeps it outside the regular modules tree and ensures it won't be ran again in a regular run. &nbsp;(As there's no easy way to write a class and only call it one time in Puppet currently we have to do things this way). &nbsp;Once created this is executed by Foreman connecting over a pre-defined SSH user and creating a temporary .pp file, running sudo puppet apply file, then cleaning up afterwards. &nbsp;Ideally we would find a way to leverage existing reports to provide results to the user.
52
53
The second type of step is the Scripted Process. &nbsp;This is pretty much the same as the previous concept by instead it builds a temporary .sh script on the host and runs that instead. &nbsp;(Maybe give the user an option to run the entire script via sudo or not to make life easy). &nbsp;Again this will either use reports or some other method to provide detailed information on how execution went. &nbsp;Rundeck allows you to see real-time tail information as well as summaries built in various ways. &nbsp;For the initial feature it would be enough to just get the output at the end of the job displayed to the user.
54
55
h4. Options
56
57
Here's where things get a little more complicated. &nbsp;It should be possible to define options as part of various steps that can be set by the user when they choose to trigger a process. &nbsp;It displays the job and the various options for them to trigger. &nbsp;I haven't thought this part fully through because I would like to, if possible, leverage all the awesome work Ohad has already done on options throughout foreman. &nbsp;It should inherit all the parameters a node has when you select where to run the job and use those for defaults for example. &nbsp;Like Rundeck it would be nice to define a pre-existing list of options or a text box for each option (so I can select /var/www/html as my destination in a text box, or prehaps select an environment from the drop-down). &nbsp;Where possible we should allow users to select options from information Foreman already has. &nbsp;I would also like to leverage facter in an easy fashion so that within my script I can simply call out something like x = $facter.operatingsystem as a bash if statement and have the script dynamically fill in all the various $facter calls.
58
59
h4. Constraints
60
61
Unlike Rundeck we should use all the awesome of Foreman to apply process constraints. &nbsp;I would like to be able to force the inclusion of a Puppet class if a job is to be run. &nbsp;Perhaps you just choose the classes that must existing on the node level for a job to be valid and then display invalid jobs in a different format. &nbsp;You get the idea, this would be a massive victory over Rundeck and be incredibly powerful. &nbsp;I would like to be able to constrain a process by things like "Must contain project::ui, project::core, be x86_64, have > 2G of ram and have a report from the node in the last 24 hours (to ensure Puppet is working)). &nbsp;Things like that would be extremely useful in my environment.
62
63
h4. Dependencies
64
65
If we were getting fancy it would be nice to define process dependencies - a process that configures an application would not be allowed to run if there was no record of the build process having been ran on a node. &nbsp;I'm not sure how clever this could get but simple 'block unless x,y,z' like the contraints. &nbsp;Maybe this just belongs up there in constraints.
66
67
h3. Launching Processes
68
69
Here we would leverage the node page as well as the multi select node options to trigger processes. &nbsp;When you drill into a node it would have an extra box called processes that would list all processes allowed by the constraints. &nbsp;You could then select and trigger multiple processes (order here would count\!) and fire them off. &nbsp;I think this would best be an option off the main node page (where the report currently is) that says Processes. &nbsp;Doesn't really fit into Edit.
70
71
h3. Monitoring Processes
72
73
This would ideally hook into reports in some fashion. &nbsp;I have no idea how this would look but you'd want to be able to see the output of the entire ssh session from start to finish I think.