blob: 76b5818e2d29028a0796a7ff5c811d9019207317 [file] [log] [blame]
martin f. krafft8acd49d2013-08-26 21:22:25 +02001================
2reclass concepts
3================
4|reclass| assumes a node-centric perspective into your inventory. This is
5obvious when you query |reclass| for node-specific information, but it might not
6be clear when you ask |reclass| to provide you with a list of groups. In that
7case, |reclass| loops over all nodes it can find in its database, reads all
8information it can find about the nodes, and finally reorders the result to
9provide a list of groups with the nodes they contain.
10
11Since the term "groups" is somewhat ambiguous, it helps to start off with
12a short glossary of |reclass|-specific terminology:
13
14============ ==============================================================
15Concept Description
16============ ==============================================================
17node A node, usually a computer in your infrastructure
18class A category, tag, feature, or role that applies to a node
19 Classes may be nested, i.e. there can be a class hierarchy
20application A specific set of behaviour to apply
21parameter Node-specific variables, with inheritance throughout the class
22 hierarchy.
23============ ==============================================================
24
25A class consists of zero or more parent classes, zero or more applications,
26and any number of parameters.
27
martin f. krafftcfc365b2013-11-27 10:21:02 +010028A class name must not contain spaces.
29
martin f. krafft8acd49d2013-08-26 21:22:25 +020030A node is almost equivalent to a class, except that it usually does not (but
31can) specify applications.
32
33When |reclass| parses a node (or class) definition and encounters a parent
34class, it recurses to this parent class first before reading any data of the
35node (or class). When |reclass| returns from the recursive, depth first walk, it
36then merges all information of the current node (or class) into the
37information it obtained during the recursion.
38
39Furthermore, a node (or class) may define a list of classes it derives from,
40in which case classes defined further down the list will be able to override
41classes further up the list.
42
43Information in this context is essentially one of a list of applications or
44a list of parameters.
45
46The interaction between the depth-first walk and the delayed merging of data
47means that the node (and any class) may override any of the data defined by
48any of the parent classes (ancestors). This is in line with the assumption
49that more specific definitions ("this specific host") should have a higher
50precedence than more general definitions ("all webservers", which includes all
51webservers in Munich, which includes "this specific host", for example).
52
53Here's a quick example, showing how parameters accumulate and can get
54replaced.
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
73At this point it should be noted that parameters whose values are lists or
74key-value pairs don't get overwritten by children classes or node definitions,
75but the information gets merged (recursively) instead.
76
77Similarly to parameters, applications also accumulate during the recursive
78walk 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
80with `~`.
81
82Finally, |reclass| happily lets you use multiple inheritance, and ensures that
83the resolution of parameters is still well-defined. Here's another example
84building 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
108It's also trivial to ensure a certain order of class evaluation. Here's
109another 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
131Now read about :doc:`operations`!
132
133.. include:: substs.inc