blob: 5685f1ddba18114eb1dc2fb4c2a447524759274c [file] [log] [blame]
martin f. krafft8acd49d2013-08-26 21:22:25 +02001=======================
2Using reclass with Salt
3=======================
4
martin f. krafftc2ff09b2013-08-27 12:46:20 +02005.. warning::
6
7 The latest release of Salt, version 0.16.3, does *not yet* include the
8 reclass adapter. You could use the ``cmd_yaml`` adapters, but at least for
9 ``ext_pillar``, they are currently not useable, as they `do not export the
10 minion ID to the command they run`_.
11
12 Your best bet at this stage is to wait for Salt 0.17, or to run Salt from
13 a Git clone, `branch "develop"`_. Sorry about that.
14
15.. _do not export the minion ID to the command they run:
16 https://github.com/saltstack/salt/issues/2276
17.. _branch "develop": https://github.com/saltstack/salt/tree/develop
18
martin f. krafft8acd49d2013-08-26 21:22:25 +020019Quick start
20-----------
21The following steps should get you up and running quickly with |reclass| and
22`Salt`_. You will need to decide for yourself where to put your |reclass|
23inventory. This can be your first ``base`` ``file_root`` (the default), or it
24could be ``/etc/reclass``, or ``/srv/salt``. The following shall assume the
25latter.
26
27Or you can also just look into ``./examples/salt`` of your |reclass|
28checkout (``/usr/share/doc/examples/salt`` on Debian-systems), where the
29following steps have already been prepared.
30
31/…/reclass refers to the location of your |reclass| checkout.
32
martin f. krafftcc8851d2013-08-27 13:43:16 +020033.. todo::
34
35 With |reclass| now in Debian, as well as installable from source, the
36 following should be checked for path consistency
37
martin f. krafft8acd49d2013-08-26 21:22:25 +020038#. Complete the installation steps described in the :doc:`installation section
39 <install>`.
40
41 Alternatively, you can also tell Salt via the master config file where to
42 look for |reclass|, but then you won't be able to interact with
43 |reclass| through the command line.
44
45#. Copy the two directories ``nodes`` and ``classes`` from the example
46 subdirectory in the |reclass| checkout to e.g. ``/srv/salt``.
47
48 It's handy to symlink |reclass|' Salt adapter itself to that directory::
49
50 $ ln -s /usr/share/reclass/reclass-salt /srv/salt/states/reclass
51
52 As you can now just inspect the data right there from the command line::
53
54 $ ./reclass --top
55
56 If you don't want to do this, you can also let |reclass| know where to
57 look for the inventory with the following contents in
58 ``$HOME/reclass-config.yml``::
59
60 storage_type: yaml_fs
61 base_inventory_uri: /srv/reclass
62
63 Or you can reuse the first entry of ``file_roots`` under ``base`` in the Salt
64 master config.
65
66 Note that ``yaml_fs`` is currently the only supported ``storage_type``, and
67 it's the default if you don't set it.
68
69#. Check out your inventory by invoking
70
71 ::
72
73 $ reclass-salt --top
74
75 which should return all the information about all defined nodes, which is
76 only ``localhost`` in the example. This is essentially the same information
77 that you would keep in your ``top.sls`` file.
78
79 If you symlinked the script to your inventory base directory, use
80
81 ::
82
83 $ ./reclass --top
84
85#. See the pillar information for ``localhost``::
86
87 $ reclass-salt --pillar localhost
88
89#. Now add |reclass| to ``/etc/salt/master``, like so::
90
91 reclass: &reclass
92 inventory_base_uri: /srv/salt
93 reclass_source_path: ~/code/reclass
94
95 master_tops:
96 […]
97 reclass: *reclass
98
99 ext_pillar:
100 - reclass: *reclass
101
martin f. krafft65ba2572013-08-29 18:34:53 +0200102 .. warning::
103
104 When using ``ext_pillar`` and/or ``master_tops``, you should make sure
105 that your ``file_roots`` paths do not contain a ``top.sls`` file. Even
106 though they ought to be able to coexist, there are a few sharp edges
107 around at the moment, so beware!
108
martin f. krafft8acd49d2013-08-26 21:22:25 +0200109 If you did not install |reclass| (but you are running it from source),
110 you can either specify the source path like above, or you can add it to
111 ``PYTHONPATH`` before invoking the Salt master, to ensure that Python can
112 find it::
113
114 PYTHONPATH=/…/reclass /etc/init.d/salt-master restart
115
116#. Provided that you have set up ``localhost`` as a Salt minion, the following
117 commands should now return the same data as above, but processed through
118 salt::
119
120 $ salt localhost pillar.items # shows just the parameters
121 $ salt localhost state.show_top # shows only the states (applications)
122
123 Alternatively, if you don't have the Salt minion running yet::
124
125 $ salt-call pillar.items # shows just the parameters
126 $ salt-call state.show_top # shows only the states (applications)
127
128#. You can also invoke |reclass| directly, which gives a slightly different
129 view onto the same data, i.e. before it has been adapted for Salt::
130
131 $ reclass --inventory
132 $ reclass --nodeinfo localhost
133
134Integration with Salt
135---------------------
136|reclass| hooks into Salt at two different points: ``master_tops`` and
137``ext_pillar``. For both, Salt provides plugins. These plugins need to know
138where to find |reclass|, so if |reclass| is not properly installed (but
139you are running it from source), make sure to export ``PYTHONPATH``
140accordingly before you start your Salt master, or specify the path in the
141master configuration file, as show above.
142
143Salt has no concept of "nodes", "applications", "parameters", and "classes".
144Therefore it is necessary to explain how those correspond to Salt. Crudely,
145the following mapping exists:
146
147================= ================
148|reclass| concept Salt terminology
149================= ================
150nodes hosts
151classes (none) [#nodegroups]_
152applications states
153parameters pillar
154================= ================
155
156.. [#nodegroups] See `Salt issue #5787`_ for steps into the direction of letting
157 |reclass| provide nodegroup information.
158
159.. _Salt issue #5787: https://github.com/saltstack/salt/issues/5787
160
161Whatever applications you define for a node will become states applicable to
162a host. If those applications are added via ancestor classes, then that's
163fine, but currently, Salt does not do anything with the classes ancestry.
164
165Similarly, all parameters that are collected and merged eventually end up in
166the pillar data of a specific node.
167
168However, the pillar data of a node include all the information about classes
169and applications, so you could theoretically use them to target your Salt
170calls at groups of nodes defined in the |reclass| inventory, e.g.
171
172::
173
174 salt -I __reclass__:classes:salt_minion test.ping
175
176Unfortunately, this does not work yet, please stay tuned, and let me know
177if you figure out a way. `Salt issue #5787`_ is also of relevance.
178
179.. include:: substs.inc
180.. include:: extrefs.inc