martin f. krafft | 42c475d | 2013-06-26 18:39:06 +0200 | [diff] [blame] | 1 | ============================================================= |
| 2 | reclass — recursive external node classification |
| 3 | ============================================================= |
| 4 | reclass is © 2007–2013 martin f. krafft <madduck@madduck.net> |
| 5 | and available under the terms of the Artistic Licence 2.0 |
| 6 | ''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''' |
| 7 | |
| 8 | Please make sure to read the generic information in the README file first, or |
| 9 | alongside this document. |
| 10 | |
| 11 | Quick start with Salt |
| 12 | ~~~~~~~~~~~~~~~~~~~~~ |
| 13 | The following steps should get you up and running quickly. You will need to |
| 14 | decide for yourself where to put your reclass inventory. This can be |
| 15 | /etc/reclass, or it could be /srv/salt, for instance if /srv/salt/states is |
| 16 | where your Salt file_roots live. The following shall assume the latter. |
| 17 | |
| 18 | Or you can also just look into ./examples/salt of your reclass checkout, |
| 19 | where the following steps have already been prepared. |
| 20 | |
| 21 | /…/reclass refers to the location of your reclass checkout. |
| 22 | |
martin f. krafft | 367532c | 2013-06-26 21:08:18 +0200 | [diff] [blame^] | 23 | 0. Run 'make' in the root of the reclass checkout (see the section |
| 24 | 'Installation' in the README file for the reason). |
| 25 | |
| 26 | 1. Symlink /…/reclass/adapters/salt to /srv/salt/states/reclass. This is not |
| 27 | at all required, because Salt interfaces with reclass as a Python module, |
| 28 | but it's handy to have the inventory within reach. |
martin f. krafft | 42c475d | 2013-06-26 18:39:06 +0200 | [diff] [blame] | 29 | |
| 30 | 2. Copy the two directories 'nodes' and 'classes' from the example |
martin f. krafft | 367532c | 2013-06-26 21:08:18 +0200 | [diff] [blame^] | 31 | subdirectory in the reclass checkout to /srv/salt/states |
martin f. krafft | 42c475d | 2013-06-26 18:39:06 +0200 | [diff] [blame] | 32 | |
| 33 | If you prefer to put those directories elsewhere, you can create |
martin f. krafft | 367532c | 2013-06-26 21:08:18 +0200 | [diff] [blame^] | 34 | /srv/salt/states/reclass-config.yml with contents such as |
martin f. krafft | 42c475d | 2013-06-26 18:39:06 +0200 | [diff] [blame] | 35 | |
| 36 | storage_type: yaml_fs |
| 37 | nodes_uri: /srv/reclass/nodes |
| 38 | classes_uri: /srv/reclass/classes |
| 39 | |
| 40 | Note that yaml_fs is currently the only supported storage_type, and it's |
| 41 | the default if you don't set it. |
| 42 | |
martin f. krafft | 367532c | 2013-06-26 21:08:18 +0200 | [diff] [blame^] | 43 | Again, this isn't really required, but it's good to get you started. If |
| 44 | you really put your inventory into /srv/reclass or /etc/reclass, you'll |
| 45 | tell the Salt master later. |
| 46 | |
martin f. krafft | 42c475d | 2013-06-26 18:39:06 +0200 | [diff] [blame] | 47 | 3. Check out your inventory by invoking |
| 48 | |
martin f. krafft | 367532c | 2013-06-26 21:08:18 +0200 | [diff] [blame^] | 49 | ./reclass --top |
martin f. krafft | 42c475d | 2013-06-26 18:39:06 +0200 | [diff] [blame] | 50 | |
martin f. krafft | 367532c | 2013-06-26 21:08:18 +0200 | [diff] [blame^] | 51 | which should return all the information about all defined nodes, which is |
| 52 | only 'localhost' in the example. This is essentially the same information |
| 53 | that you would keep in your top.sls file. |
martin f. krafft | 42c475d | 2013-06-26 18:39:06 +0200 | [diff] [blame] | 54 | |
martin f. krafft | 367532c | 2013-06-26 21:08:18 +0200 | [diff] [blame^] | 55 | 4. See the pillar information for 'localhost': |
martin f. krafft | 42c475d | 2013-06-26 18:39:06 +0200 | [diff] [blame] | 56 | |
martin f. krafft | 367532c | 2013-06-26 21:08:18 +0200 | [diff] [blame^] | 57 | ./reclass --pillar localhost |
martin f. krafft | 42c475d | 2013-06-26 18:39:06 +0200 | [diff] [blame] | 58 | |
martin f. krafft | 367532c | 2013-06-26 21:08:18 +0200 | [diff] [blame^] | 59 | This is the so-called pillar-data for the named host. |
martin f. krafft | 42c475d | 2013-06-26 18:39:06 +0200 | [diff] [blame] | 60 | |
martin f. krafft | 367532c | 2013-06-26 21:08:18 +0200 | [diff] [blame^] | 61 | 5. Now add reclass to /etc/salt/master, like so: |
martin f. krafft | 42c475d | 2013-06-26 18:39:06 +0200 | [diff] [blame] | 62 | |
martin f. krafft | 367532c | 2013-06-26 21:08:18 +0200 | [diff] [blame^] | 63 | master_tops: |
| 64 | […] |
| 65 | reclass: |
| 66 | inventory_base_uri: /srv/salt |
martin f. krafft | 42c475d | 2013-06-26 18:39:06 +0200 | [diff] [blame] | 67 | |
martin f. krafft | 367532c | 2013-06-26 21:08:18 +0200 | [diff] [blame^] | 68 | ext_pillar: |
| 69 | reclass: |
| 70 | inventory_base_uri: /srv/salt |
| 71 | |
| 72 | Currently, there is no way to unify these configuration data, but it's |
| 73 | hardly much to duplicate. In the future, I may provide for a global |
| 74 | 'reclass' key, but for now you will have to add the data twice. |
| 75 | |
| 76 | Now restart your Salt master and make sure that reclass is in the |
| 77 | PYTHONPATH, so if it's not properly installed (but you are running it |
| 78 | from source), do this: |
| 79 | |
| 80 | PYTHONPATH=/…/reclass /etc/init.d/salt-master restart |
| 81 | |
| 82 | 6. Provided that you have set up 'localhost' as a Salt minion, the following |
| 83 | commands should now return the same data as above, but processed through |
| 84 | salt: |
| 85 | |
| 86 | salt localhost pillar.items # shows just the parameters |
| 87 | salt localhost state.show_top # shows only the states (applications) |
| 88 | |
| 89 | Alternatively, if you don't have the Salt minion running yet: |
| 90 | |
| 91 | salt-call pillar.items # shows just the parameters |
| 92 | salt-call state.show_top # shows only the states (applications) |
| 93 | |
| 94 | 7. You can also invoke reclass directly, which gives a slightly different |
| 95 | view onto the same data, i.e. before it has been adapted for Salt: |
martin f. krafft | 42c475d | 2013-06-26 18:39:06 +0200 | [diff] [blame] | 96 | |
| 97 | /…/reclass.py --pretty-print --inventory |
| 98 | /…/reclass.py --pretty-print --nodeinfo localhost |
| 99 | |
| 100 | Integration with Salt |
| 101 | ~~~~~~~~~~~~~~~~~~~~~ |
martin f. krafft | 367532c | 2013-06-26 21:08:18 +0200 | [diff] [blame^] | 102 | reclass hooks into Salt at two different points: master_tops and ext_pillar. |
| 103 | For both, Salt provides plugins. These plugins need to know where to find |
| 104 | reclass, so if reclass is not properly installed (but you are running it |
| 105 | from source), make sure to export PYTHONPATH accordingly before you start your |
| 106 | Salt master. |
martin f. krafft | 42c475d | 2013-06-26 18:39:06 +0200 | [diff] [blame] | 107 | |
martin f. krafft | 367532c | 2013-06-26 21:08:18 +0200 | [diff] [blame^] | 108 | Salt has no concept of "nodes", "applications", "parameters", and "classes". |
| 109 | Therefore it is necessary to explain how those correspond to Salt. Crudely, |
| 110 | the following mapping exists: |
martin f. krafft | 42c475d | 2013-06-26 18:39:06 +0200 | [diff] [blame] | 111 | |
| 112 | nodes hosts |
martin f. krafft | 367532c | 2013-06-26 21:08:18 +0200 | [diff] [blame^] | 113 | classes - [*] |
| 114 | applications states |
| 115 | parameters pillar |
martin f. krafft | 42c475d | 2013-06-26 18:39:06 +0200 | [diff] [blame] | 116 | |
martin f. krafft | 367532c | 2013-06-26 21:08:18 +0200 | [diff] [blame^] | 117 | [*] See Salt issue #5787 for steps into the direction of letting reclass |
| 118 | provide nodegroup information. |
martin f. krafft | 42c475d | 2013-06-26 18:39:06 +0200 | [diff] [blame] | 119 | |
martin f. krafft | 367532c | 2013-06-26 21:08:18 +0200 | [diff] [blame^] | 120 | Whatever applications you define for a node will become states applicable to |
| 121 | a host. If those applications are added via ancestor classes, then that's |
| 122 | fine, but currently, Salt does not do anything with the classes ancestry. |
martin f. krafft | 42c475d | 2013-06-26 18:39:06 +0200 | [diff] [blame] | 123 | |
martin f. krafft | 367532c | 2013-06-26 21:08:18 +0200 | [diff] [blame^] | 124 | Similarly, all parameters that are collected and merged eventually end up in |
| 125 | the pillar data of a specific node. |
martin f. krafft | 42c475d | 2013-06-26 18:39:06 +0200 | [diff] [blame] | 126 | |
martin f. krafft | 367532c | 2013-06-26 21:08:18 +0200 | [diff] [blame^] | 127 | However, the pillar data of a node include all the information about classes |
| 128 | and applications, so you can use them to target your Salt calls at groups of |
| 129 | nodes defined in the reclass inventory, e.g. |
martin f. krafft | 42c475d | 2013-06-26 18:39:06 +0200 | [diff] [blame] | 130 | |
martin f. krafft | 367532c | 2013-06-26 21:08:18 +0200 | [diff] [blame^] | 131 | salt -I __reclass__:classes:salt_minion test.ping |
martin f. krafft | 42c475d | 2013-06-26 18:39:06 +0200 | [diff] [blame] | 132 | |
martin f. krafft | 367532c | 2013-06-26 21:08:18 +0200 | [diff] [blame^] | 133 | Unfortunately, this does not work yet, please stay tuned, and let me know |
| 134 | if you figure out a way. Salt issue #5787 is also of relevance. |
martin f. krafft | 42c475d | 2013-06-26 18:39:06 +0200 | [diff] [blame] | 135 | |
martin f. krafft | 367532c | 2013-06-26 21:08:18 +0200 | [diff] [blame^] | 136 | It will also be possible to include Jinja2-style variables in parameter |
| 137 | values. This is especially powerful in combination with the recursive merging, |
| 138 | e.g. |
martin f. krafft | 42c475d | 2013-06-26 18:39:06 +0200 | [diff] [blame] | 139 | |
| 140 | parameters: |
| 141 | motd: |
martin f. krafft | 367532c | 2013-06-26 21:08:18 +0200 | [diff] [blame^] | 142 | greeting: Welcome to {{ grains.fqdn }}! |
martin f. krafft | 42c475d | 2013-06-26 18:39:06 +0200 | [diff] [blame] | 143 | closing: This system is part of {{ realm }} |
| 144 | |
| 145 | Now you just need to specify realm somewhere. The reference can reside in |
| 146 | a parent class, while the variable is defined e.g. in the node. |
martin f. krafft | 367532c | 2013-06-26 21:08:18 +0200 | [diff] [blame^] | 147 | |
| 148 | This is also not yet working. The main reason is that the expansion cannot |
| 149 | happen at the YAML-file level, because that would cast most types to strings. |
| 150 | Instead, the interpolation needs to happen at the data structure level inside |
| 151 | reclass, or maybe at the adapter level, reusing the templating of Salt. This |
| 152 | will require some more thought, but it's on the horizon… |