blob: 25bd53fb278080014f24220a33f379d75133ecf2 [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
martin f. krafftbee6bbd2013-12-26 16:58:56 +1300130Configuration file and master configuration
131-------------------------------------------
132Even though the Salt adapter of |reclass| looks for and reads the
133:doc:`configuration file <configfile>`, a better means to pass information to
134the adapter is via Salt's master configuration file, as shown above. Not all
135configuration options can be passed this way (e.g. ``output`` is hardcoded to
136YAML, which Salt uses), but it *is* possible to specify :doc:`class mappings
martin f. krafftf7aaa9b2013-12-26 17:04:58 +1300137<operations>` next to all the storage-specific options.
martin f. krafftbee6bbd2013-12-26 16:58:56 +1300138
139.. warning::
140
141 The Salt CLI adapter does *not* read Salt's master configuration, so if you
142 are calling ``reclass-salt`` from the command-line (the CLI exists for
143 debugging purposes, mainly), be aware that it will be run in a different
144 environment than when Salt queries reclass directly.
145
martin f. krafft8acd49d2013-08-26 21:22:25 +0200146Integration with Salt
147---------------------
148|reclass| hooks into Salt at two different points: ``master_tops`` and
149``ext_pillar``. For both, Salt provides plugins. These plugins need to know
150where to find |reclass|, so if |reclass| is not properly installed (but
151you are running it from source), make sure to export ``PYTHONPATH``
152accordingly before you start your Salt master, or specify the path in the
153master configuration file, as show above.
154
155Salt has no concept of "nodes", "applications", "parameters", and "classes".
156Therefore it is necessary to explain how those correspond to Salt. Crudely,
157the following mapping exists:
158
159================= ================
160|reclass| concept Salt terminology
161================= ================
162nodes hosts
163classes (none) [#nodegroups]_
164applications states
165parameters pillar
166================= ================
167
168.. [#nodegroups] See `Salt issue #5787`_ for steps into the direction of letting
169 |reclass| provide nodegroup information.
170
171.. _Salt issue #5787: https://github.com/saltstack/salt/issues/5787
172
173Whatever applications you define for a node will become states applicable to
174a host. If those applications are added via ancestor classes, then that's
175fine, but currently, Salt does not do anything with the classes ancestry.
176
177Similarly, all parameters that are collected and merged eventually end up in
178the pillar data of a specific node.
179
180However, the pillar data of a node include all the information about classes
181and applications, so you could theoretically use them to target your Salt
182calls at groups of nodes defined in the |reclass| inventory, e.g.
183
184::
185
186 salt -I __reclass__:classes:salt_minion test.ping
187
188Unfortunately, this does not work yet, please stay tuned, and let me know
189if you figure out a way. `Salt issue #5787`_ is also of relevance.
190
191.. include:: substs.inc
192.. include:: extrefs.inc