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