blob: 9d9292fdca4e1ba946959b5cd800190f196fa369 [file] [log] [blame]
martin f. krafft42c475d2013-06-26 18:39:06 +02001=============================================================
2 reclass recursive external node classification
3=============================================================
4reclass is © 20072013 martin f. krafft <madduck@madduck.net>
5and available under the terms of the Artistic Licence 2.0
6'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
7
8Please make sure to read the generic information in the README file first, or
9alongside this document.
10
11Quick start with Salt
12~~~~~~~~~~~~~~~~~~~~~
13The following steps should get you up and running quickly. You will need to
14decide for yourself where to put your reclass inventory. This can be
15/etc/reclass, or it could be /srv/salt, for instance if /srv/salt/states is
16where your Salt file_roots live. The following shall assume the latter.
17
18Or you can also just look into ./examples/salt of your reclass checkout,
19where the following steps have already been prepared.
20
21/…/reclass refers to the location of your reclass checkout.
22
martin f. krafft367532c2013-06-26 21:08:18 +020023 0. Run 'make' in the root of the reclass checkout (see the section
24 'Installation' in the README file for the reason).
25
26 1. Symlink /…/reclass/adapters/salt to /srv/salt/states/reclass. This is not
27 at all required, because Salt interfaces with reclass as a Python module,
28 but it's handy to have the inventory within reach.
martin f. krafft42c475d2013-06-26 18:39:06 +020029
30 2. Copy the two directories 'nodes' and 'classes' from the example
martin f. krafft367532c2013-06-26 21:08:18 +020031 subdirectory in the reclass checkout to /srv/salt/states
martin f. krafft42c475d2013-06-26 18:39:06 +020032
33 If you prefer to put those directories elsewhere, you can create
martin f. krafft367532c2013-06-26 21:08:18 +020034 /srv/salt/states/reclass-config.yml with contents such as
martin f. krafft42c475d2013-06-26 18:39:06 +020035
36 storage_type: yaml_fs
37 nodes_uri: /srv/reclass/nodes
38 classes_uri: /srv/reclass/classes
39
40 Note that yaml_fs is currently the only supported storage_type, and it's
41 the default if you don't set it.
42
martin f. krafft367532c2013-06-26 21:08:18 +020043 Again, this isn't really required, but it's good to get you started. If
44 you really put your inventory into /srv/reclass or /etc/reclass, you'll
45 tell the Salt master later.
46
martin f. krafft42c475d2013-06-26 18:39:06 +020047 3. Check out your inventory by invoking
48
martin f. krafft367532c2013-06-26 21:08:18 +020049 ./reclass --top
martin f. krafft42c475d2013-06-26 18:39:06 +020050
martin f. krafft367532c2013-06-26 21:08:18 +020051 which should return all the information about all defined nodes, which is
52 only 'localhost' in the example. This is essentially the same information
53 that you would keep in your top.sls file.
martin f. krafft42c475d2013-06-26 18:39:06 +020054
martin f. krafft367532c2013-06-26 21:08:18 +020055 4. See the pillar information for 'localhost':
martin f. krafft42c475d2013-06-26 18:39:06 +020056
martin f. krafft367532c2013-06-26 21:08:18 +020057 ./reclass --pillar localhost
martin f. krafft42c475d2013-06-26 18:39:06 +020058
martin f. krafft367532c2013-06-26 21:08:18 +020059 This is the so-called pillar-data for the named host.
martin f. krafft42c475d2013-06-26 18:39:06 +020060
martin f. krafft367532c2013-06-26 21:08:18 +020061 5. Now add reclass to /etc/salt/master, like so:
martin f. krafft42c475d2013-06-26 18:39:06 +020062
martin f. krafft367532c2013-06-26 21:08:18 +020063 master_tops:
64 […]
65 reclass:
66 inventory_base_uri: /srv/salt
martin f. krafft42c475d2013-06-26 18:39:06 +020067
martin f. krafft367532c2013-06-26 21:08:18 +020068 ext_pillar:
69 reclass:
70 inventory_base_uri: /srv/salt
71
72 Currently, there is no way to unify these configuration data, but it's
73 hardly much to duplicate. In the future, I may provide for a global
74 'reclass' key, but for now you will have to add the data twice.
75
76 Now restart your Salt master and make sure that reclass is in the
77 PYTHONPATH, so if it's not properly installed (but you are running it
78 from source), do this:
79
80 PYTHONPATH=/…/reclass /etc/init.d/salt-master restart
81
82 6. Provided that you have set up 'localhost' as a Salt minion, the following
83 commands should now return the same data as above, but processed through
84 salt:
85
86 salt localhost pillar.items # shows just the parameters
87 salt localhost state.show_top # shows only the states (applications)
88
89 Alternatively, if you don't have the Salt minion running yet:
90
91 salt-call pillar.items # shows just the parameters
92 salt-call state.show_top # shows only the states (applications)
93
94 7. You can also invoke reclass directly, which gives a slightly different
95 view onto the same data, i.e. before it has been adapted for Salt:
martin f. krafft42c475d2013-06-26 18:39:06 +020096
97 /…/reclass.py --pretty-print --inventory
98 /…/reclass.py --pretty-print --nodeinfo localhost
99
100Integration with Salt
101~~~~~~~~~~~~~~~~~~~~~
martin f. krafft367532c2013-06-26 21:08:18 +0200102reclass hooks into Salt at two different points: master_tops and ext_pillar.
103For both, Salt provides plugins. These plugins need to know where to find
104reclass, so if reclass is not properly installed (but you are running it
105from source), make sure to export PYTHONPATH accordingly before you start your
106Salt master.
martin f. krafft42c475d2013-06-26 18:39:06 +0200107
martin f. krafft367532c2013-06-26 21:08:18 +0200108Salt has no concept of "nodes", "applications", "parameters", and "classes".
109Therefore it is necessary to explain how those correspond to Salt. Crudely,
110the following mapping exists:
martin f. krafft42c475d2013-06-26 18:39:06 +0200111
112 nodes hosts
martin f. krafft367532c2013-06-26 21:08:18 +0200113 classes - [*]
114 applications states
115 parameters pillar
martin f. krafft42c475d2013-06-26 18:39:06 +0200116
martin f. krafft367532c2013-06-26 21:08:18 +0200117[*] See Salt issue #5787 for steps into the direction of letting reclass
118provide nodegroup information.
martin f. krafft42c475d2013-06-26 18:39:06 +0200119
martin f. krafft367532c2013-06-26 21:08:18 +0200120Whatever applications you define for a node will become states applicable to
121a host. If those applications are added via ancestor classes, then that's
122fine, but currently, Salt does not do anything with the classes ancestry.
martin f. krafft42c475d2013-06-26 18:39:06 +0200123
martin f. krafft367532c2013-06-26 21:08:18 +0200124Similarly, all parameters that are collected and merged eventually end up in
125the pillar data of a specific node.
martin f. krafft42c475d2013-06-26 18:39:06 +0200126
martin f. krafft367532c2013-06-26 21:08:18 +0200127However, the pillar data of a node include all the information about classes
128and applications, so you can use them to target your Salt calls at groups of
129nodes defined in the reclass inventory, e.g.
martin f. krafft42c475d2013-06-26 18:39:06 +0200130
martin f. krafft367532c2013-06-26 21:08:18 +0200131 salt -I __reclass__:classes:salt_minion test.ping
martin f. krafft42c475d2013-06-26 18:39:06 +0200132
martin f. krafft367532c2013-06-26 21:08:18 +0200133Unfortunately, this does not work yet, please stay tuned, and let me know
134if you figure out a way. Salt issue #5787 is also of relevance.
martin f. krafft42c475d2013-06-26 18:39:06 +0200135
martin f. krafft367532c2013-06-26 21:08:18 +0200136It will also be possible to include Jinja2-style variables in parameter
137values. This is especially powerful in combination with the recursive merging,
138e.g.
martin f. krafft42c475d2013-06-26 18:39:06 +0200139
140 parameters:
141 motd:
martin f. krafft367532c2013-06-26 21:08:18 +0200142 greeting: Welcome to {{ grains.fqdn }}!
martin f. krafft42c475d2013-06-26 18:39:06 +0200143 closing: This system is part of {{ realm }}
144
145Now you just need to specify realm somewhere. The reference can reside in
146a parent class, while the variable is defined e.g. in the node.
martin f. krafft367532c2013-06-26 21:08:18 +0200147
148This is also not yet working. The main reason is that the expansion cannot
149happen at the YAML-file level, because that would cast most types to strings.
150Instead, the interpolation needs to happen at the data structure level inside
151reclass, or maybe at the adapter level, reusing the templating of Salt. This
152will require some more thought, but it's on the horizon