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