martin f. krafft | 8acd49d | 2013-08-26 21:22:25 +0200 | [diff] [blame] | 1 | ======================= |
| 2 | Using reclass with Salt |
| 3 | ======================= |
| 4 | |
martin f. krafft | c2ff09b | 2013-08-27 12:46:20 +0200 | [diff] [blame] | 5 | .. warning:: |
| 6 | |
martin f. krafft | bc9b8d3 | 2013-10-18 06:44:26 +0200 | [diff] [blame] | 7 | 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. krafft | c2ff09b | 2013-08-27 12:46:20 +0200 | [diff] [blame] | 9 | ``ext_pillar``, they are currently not useable, as they `do not export the |
| 10 | minion ID to the command they run`_. |
| 11 | |
martin f. krafft | c2ff09b | 2013-08-27 12:46:20 +0200 | [diff] [blame] | 12 | .. _do not export the minion ID to the command they run: |
| 13 | https://github.com/saltstack/salt/issues/2276 |
martin f. krafft | c2ff09b | 2013-08-27 12:46:20 +0200 | [diff] [blame] | 14 | |
martin f. krafft | 8acd49d | 2013-08-26 21:22:25 +0200 | [diff] [blame] | 15 | Quick start |
| 16 | ----------- |
| 17 | The 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| |
| 19 | inventory. This can be your first ``base`` ``file_root`` (the default), or it |
| 20 | could be ``/etc/reclass``, or ``/srv/salt``. The following shall assume the |
| 21 | latter. |
| 22 | |
| 23 | Or you can also just look into ``./examples/salt`` of your |reclass| |
| 24 | checkout (``/usr/share/doc/examples/salt`` on Debian-systems), where the |
| 25 | following steps have already been prepared. |
| 26 | |
| 27 | /…/reclass refers to the location of your |reclass| checkout. |
| 28 | |
martin f. krafft | cc8851d | 2013-08-27 13:43:16 +0200 | [diff] [blame] | 29 | .. 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. krafft | 8acd49d | 2013-08-26 21:22:25 +0200 | [diff] [blame] | 34 | #. 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. krafft | 65ba257 | 2013-08-29 18:34:53 +0200 | [diff] [blame] | 98 | .. 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. krafft | 8acd49d | 2013-08-26 21:22:25 +0200 | [diff] [blame] | 105 | 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. krafft | bee6bbd | 2013-12-26 16:58:56 +1300 | [diff] [blame] | 130 | Configuration file and master configuration |
| 131 | ------------------------------------------- |
| 132 | Even though the Salt adapter of |reclass| looks for and reads the |
| 133 | :doc:`configuration file <configfile>`, a better means to pass information to |
| 134 | the adapter is via Salt's master configuration file, as shown above. Not all |
| 135 | configuration options can be passed this way (e.g. ``output`` is hardcoded to |
| 136 | YAML, which Salt uses), but it *is* possible to specify :doc:`class mappings |
martin f. krafft | f7aaa9b | 2013-12-26 17:04:58 +1300 | [diff] [blame] | 137 | <operations>` next to all the storage-specific options. |
martin f. krafft | bee6bbd | 2013-12-26 16:58:56 +1300 | [diff] [blame] | 138 | |
| 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. krafft | 8acd49d | 2013-08-26 21:22:25 +0200 | [diff] [blame] | 146 | Integration 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 |
| 150 | where to find |reclass|, so if |reclass| is not properly installed (but |
| 151 | you are running it from source), make sure to export ``PYTHONPATH`` |
| 152 | accordingly before you start your Salt master, or specify the path in the |
| 153 | master configuration file, as show above. |
| 154 | |
| 155 | Salt has no concept of "nodes", "applications", "parameters", and "classes". |
| 156 | Therefore it is necessary to explain how those correspond to Salt. Crudely, |
| 157 | the following mapping exists: |
| 158 | |
| 159 | ================= ================ |
| 160 | |reclass| concept Salt terminology |
| 161 | ================= ================ |
| 162 | nodes hosts |
| 163 | classes (none) [#nodegroups]_ |
| 164 | applications states |
| 165 | parameters pillar |
martin f. krafft | d48a46e | 2014-01-03 14:32:49 +1300 | [diff] [blame] | 166 | environment environment |
martin f. krafft | 8acd49d | 2013-08-26 21:22:25 +0200 | [diff] [blame] | 167 | ================= ================ |
| 168 | |
| 169 | .. [#nodegroups] See `Salt issue #5787`_ for steps into the direction of letting |
| 170 | |reclass| provide nodegroup information. |
| 171 | |
| 172 | .. _Salt issue #5787: https://github.com/saltstack/salt/issues/5787 |
| 173 | |
| 174 | Whatever applications you define for a node will become states applicable to |
| 175 | a host. If those applications are added via ancestor classes, then that's |
| 176 | fine, but currently, Salt does not do anything with the classes ancestry. |
| 177 | |
| 178 | Similarly, all parameters that are collected and merged eventually end up in |
| 179 | the pillar data of a specific node. |
| 180 | |
martin f. krafft | 758e503 | 2014-03-01 14:40:56 +0100 | [diff] [blame^] | 181 | The pillar data of a node include all the information about classes and |
| 182 | applications, so you could theoretically use them to target your Salt calls at |
| 183 | groups of nodes defined in the |reclass| inventory, e.g. |
martin f. krafft | 8acd49d | 2013-08-26 21:22:25 +0200 | [diff] [blame] | 184 | |
| 185 | :: |
| 186 | |
| 187 | salt -I __reclass__:classes:salt_minion test.ping |
| 188 | |
| 189 | Unfortunately, this does not work yet, please stay tuned, and let me know |
| 190 | if you figure out a way. `Salt issue #5787`_ is also of relevance. |
| 191 | |
martin f. krafft | 758e503 | 2014-03-01 14:40:56 +0100 | [diff] [blame^] | 192 | Optionally, data from pillars that run before the |reclass| ``ext_pillar`` |
| 193 | (i.e. Salt's builtin ``pillar_roots``, as well as other ``ext_pillar`` modules |
| 194 | listed before the ``reclass_adapter``) can be made available to |reclass|. |
| 195 | Please use this with caution as referencing data from Salt in the inventory |
| 196 | will make it harder or impossible to run |reclass| in other environments. This |
| 197 | feature is therefore turned off by default and must be explicitly enabled in |
| 198 | the Salt master configuration file, like this:: |
| 199 | |
| 200 | reclass: &reclass |
| 201 | […] |
| 202 | propagate_pillar_data_to_reclass: True |
| 203 | |
martin f. krafft | 8acd49d | 2013-08-26 21:22:25 +0200 | [diff] [blame] | 204 | .. include:: substs.inc |
| 205 | .. include:: extrefs.inc |