blob: 5a6dbd6a6a11b8613490602317f32b2e9ec56ae1 [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
102 If you did not install |reclass| (but you are running it from source),
103 you can either specify the source path like above, or you can add it to
104 ``PYTHONPATH`` before invoking the Salt master, to ensure that Python can
105 find it::
106
107 PYTHONPATH=/…/reclass /etc/init.d/salt-master restart
108
109#. Provided that you have set up ``localhost`` as a Salt minion, the following
110 commands should now return the same data as above, but processed through
111 salt::
112
113 $ salt localhost pillar.items # shows just the parameters
114 $ salt localhost state.show_top # shows only the states (applications)
115
116 Alternatively, if you don't have the Salt minion running yet::
117
118 $ salt-call pillar.items # shows just the parameters
119 $ salt-call state.show_top # shows only the states (applications)
120
121#. You can also invoke |reclass| directly, which gives a slightly different
122 view onto the same data, i.e. before it has been adapted for Salt::
123
124 $ reclass --inventory
125 $ reclass --nodeinfo localhost
126
127Integration with Salt
128---------------------
129|reclass| hooks into Salt at two different points: ``master_tops`` and
130``ext_pillar``. For both, Salt provides plugins. These plugins need to know
131where to find |reclass|, so if |reclass| is not properly installed (but
132you are running it from source), make sure to export ``PYTHONPATH``
133accordingly before you start your Salt master, or specify the path in the
134master configuration file, as show above.
135
136Salt has no concept of "nodes", "applications", "parameters", and "classes".
137Therefore it is necessary to explain how those correspond to Salt. Crudely,
138the following mapping exists:
139
140================= ================
141|reclass| concept Salt terminology
142================= ================
143nodes hosts
144classes (none) [#nodegroups]_
145applications states
146parameters pillar
147================= ================
148
149.. [#nodegroups] See `Salt issue #5787`_ for steps into the direction of letting
150 |reclass| provide nodegroup information.
151
152.. _Salt issue #5787: https://github.com/saltstack/salt/issues/5787
153
154Whatever applications you define for a node will become states applicable to
155a host. If those applications are added via ancestor classes, then that's
156fine, but currently, Salt does not do anything with the classes ancestry.
157
158Similarly, all parameters that are collected and merged eventually end up in
159the pillar data of a specific node.
160
161However, the pillar data of a node include all the information about classes
162and applications, so you could theoretically use them to target your Salt
163calls at groups of nodes defined in the |reclass| inventory, e.g.
164
165::
166
167 salt -I __reclass__:classes:salt_minion test.ping
168
169Unfortunately, this does not work yet, please stay tuned, and let me know
170if you figure out a way. `Salt issue #5787`_ is also of relevance.
171
172.. include:: substs.inc
173.. include:: extrefs.inc