martin f. krafft | 8acd49d | 2013-08-26 21:22:25 +0200 | [diff] [blame] | 1 | ================ |
| 2 | reclass concepts |
| 3 | ================ |
| 4 | |reclass| assumes a node-centric perspective into your inventory. This is |
| 5 | obvious when you query |reclass| for node-specific information, but it might not |
| 6 | be clear when you ask |reclass| to provide you with a list of groups. In that |
| 7 | case, |reclass| loops over all nodes it can find in its database, reads all |
| 8 | information it can find about the nodes, and finally reorders the result to |
| 9 | provide a list of groups with the nodes they contain. |
| 10 | |
| 11 | Since the term "groups" is somewhat ambiguous, it helps to start off with |
| 12 | a short glossary of |reclass|-specific terminology: |
| 13 | |
| 14 | ============ ============================================================== |
| 15 | Concept Description |
| 16 | ============ ============================================================== |
| 17 | node A node, usually a computer in your infrastructure |
| 18 | class A category, tag, feature, or role that applies to a node |
| 19 | Classes may be nested, i.e. there can be a class hierarchy |
| 20 | application A specific set of behaviour to apply |
| 21 | parameter Node-specific variables, with inheritance throughout the class |
| 22 | hierarchy. |
| 23 | ============ ============================================================== |
| 24 | |
| 25 | A class consists of zero or more parent classes, zero or more applications, |
| 26 | and any number of parameters. |
| 27 | |
martin f. krafft | cfc365b | 2013-11-27 10:21:02 +0100 | [diff] [blame^] | 28 | A class name must not contain spaces. |
| 29 | |
martin f. krafft | 8acd49d | 2013-08-26 21:22:25 +0200 | [diff] [blame] | 30 | A node is almost equivalent to a class, except that it usually does not (but |
| 31 | can) specify applications. |
| 32 | |
| 33 | When |reclass| parses a node (or class) definition and encounters a parent |
| 34 | class, it recurses to this parent class first before reading any data of the |
| 35 | node (or class). When |reclass| returns from the recursive, depth first walk, it |
| 36 | then merges all information of the current node (or class) into the |
| 37 | information it obtained during the recursion. |
| 38 | |
| 39 | Furthermore, a node (or class) may define a list of classes it derives from, |
| 40 | in which case classes defined further down the list will be able to override |
| 41 | classes further up the list. |
| 42 | |
| 43 | Information in this context is essentially one of a list of applications or |
| 44 | a list of parameters. |
| 45 | |
| 46 | The interaction between the depth-first walk and the delayed merging of data |
| 47 | means that the node (and any class) may override any of the data defined by |
| 48 | any of the parent classes (ancestors). This is in line with the assumption |
| 49 | that more specific definitions ("this specific host") should have a higher |
| 50 | precedence than more general definitions ("all webservers", which includes all |
| 51 | webservers in Munich, which includes "this specific host", for example). |
| 52 | |
| 53 | Here's a quick example, showing how parameters accumulate and can get |
| 54 | replaced. |
| 55 | |
| 56 | All "unixnodes" (i.e. nodes who have the ``unixnode`` class in their |
| 57 | ancestry) have ``/etc/motd`` centrally-managed (through the ``motd`` |
| 58 | application), and the `unixnode` class definition provides a generic |
| 59 | message-of-the-day to be put into this file. |
| 60 | |
| 61 | All descendants of the class ``debiannode``, a descendant of ``unixnode``, |
| 62 | should include the Debian codename in this message, so the |
| 63 | message-of-the-day is overwritten in the ``debiannodes`` class. |
| 64 | |
| 65 | The node ``quantum.example.org`` (a `debiannode`) will have a scheduled |
| 66 | downtime this weekend, so until Monday, an appropriate message-of-the-day is |
| 67 | added to the node definition. |
| 68 | |
| 69 | When the ``motd`` application runs, it receives the appropriate |
| 70 | message-of-the-day (from ``quantum.example.org`` when run on that node) and |
| 71 | writes it into ``/etc/motd``. |
| 72 | |
| 73 | At this point it should be noted that parameters whose values are lists or |
| 74 | key-value pairs don't get overwritten by children classes or node definitions, |
| 75 | but the information gets merged (recursively) instead. |
| 76 | |
| 77 | Similarly to parameters, applications also accumulate during the recursive |
| 78 | walk through the class ancestry. It is possible for a node or child class to |
| 79 | *remove* an application added by a parent class, by prefixing the application |
| 80 | with `~`. |
| 81 | |
| 82 | Finally, |reclass| happily lets you use multiple inheritance, and ensures that |
| 83 | the resolution of parameters is still well-defined. Here's another example |
| 84 | building upon the one about ``/etc/motd`` above: |
| 85 | |
| 86 | ``quantum.example.org`` (which is back up and therefore its node definition |
| 87 | no longer contains a message-of-the-day) is at a site in Munich. Therefore, |
| 88 | it is a child of the class ``hosted@munich``. This class is independent of |
| 89 | the ``unixnode`` hierarchy, ``quantum.example.org`` derives from both. |
| 90 | |
| 91 | In this example infrastructure, ``hosted@munich`` is more specific than |
| 92 | ``debiannode`` because there are plenty of Debian nodes at other sites (and |
| 93 | some non-Debian nodes in Munich). Therefore, ``quantum.example.org`` derives |
| 94 | from ``hosted@munich`` _after_ ``debiannodes``. |
| 95 | |
| 96 | When an electricity outage is expected over the weekend in Munich, the admin |
| 97 | can change the message-of-the-day in the ``hosted@munich`` class, and it |
| 98 | will apply to all hosts in Munich. |
| 99 | |
| 100 | However, not all hosts in Munich have ``/etc/motd``, because some of them |
| 101 | are of class ``windowsnode``. Since the ``windowsnode`` ancestry does not |
| 102 | specify the ``motd`` application, those hosts have access to the |
| 103 | message-of-the-day in the node variables, but the message won't get used… |
| 104 | |
| 105 | … unless, of course, ``windowsnode`` specified a Windows-specific |
| 106 | application to bring such notices to the attention of the user. |
| 107 | |
| 108 | It's also trivial to ensure a certain order of class evaluation. Here's |
| 109 | another example: |
| 110 | |
| 111 | The ``ssh.server`` class defines the ``permit_root_login`` parameter to ``no``. |
| 112 | |
| 113 | The ``backuppc.client`` class defines the parameter to ``without-password``, |
| 114 | because the BackupPC server might need to log in to the host as root. |
| 115 | |
| 116 | Now, what happens if the admin accidentally provides the following two |
| 117 | classes? |
| 118 | |
| 119 | - ``backuppc.client`` |
| 120 | - ``ssh.server`` |
| 121 | |
| 122 | Theoretically, this would mean ``permit_root_login`` gets set to ``no``. |
| 123 | |
| 124 | However, since all ``backuppc.client`` nodes need ``ssh.server`` (at least |
| 125 | in most setups), the class ``backuppc.client`` itself derives from |
| 126 | ``ssh.server``, ensuring that it gets parsed before ``backuppc.client``. |
| 127 | |
| 128 | When |reclass| returns to the node and encounters the ``ssh.server`` class |
| 129 | defined there, it simply skips it, as it's already been processed. |
| 130 | |
| 131 | Now read about :doc:`operations`! |
| 132 | |
| 133 | .. include:: substs.inc |