blob: 42e8a8642a9237d55e60726d0489e0234a7e214f [file] [log] [blame]
martin f. krafft8acd49d2013-08-26 21:22:25 +02001==================
2reclass operations
3==================
4
martin f. krafftf4320532013-11-30 17:00:37 +01005YAML FS storage
6---------------
martin f. krafft8acd49d2013-08-26 21:22:25 +02007While |reclass| has been built to support different storage backends through
8plugins, currently only the ``yaml_fs`` storage backend exists. This is a very
9simple, yet powerful, YAML-based backend, using flat files on the filesystem
10(as suggested by the ``_fs`` postfix).
11
12``yaml_fs`` works with two directories, one for node definitions, and another
martin f. krafft16c93802013-11-30 13:23:16 +010013for class definitions. The two directories must not be the same, nor can one
14be a parent of the other.
martin f. krafft8acd49d2013-08-26 21:22:25 +020015
16Files in those directories are YAML-files, specifying key-value pairs. The
17following three keys are read by |reclass|:
18
19============ ================================================================
20Key Description
21============ ================================================================
22classes a list of parent classes
23appliations a list of applications to append to the applications defined by
24 ancestors. If an application name starts with ``~``, it would
25 remove this application from the list, if it had already been
26 added — but it does not prevent a future addition.
27 E.g. ``~firewalled``
28parameters key-value pairs to set defaults in class definitions, override
29 existing data, or provide node-specific information in node
30 specifications.
31 \
32 By convention, parameters corresponding to an application
33 should be provided as subkey-value pairs, keyed by the name of
34 the application, e.g.::
35
36 applications:
37 - ssh.server
38 parameters:
39 ssh.server:
40 permit_root_login: no
martin f. krafftd48a46e2014-01-03 14:32:49 +130041environment only relevant for nodes, this allows to specify an "environment"
42 into which the node definition is supposed to be place.
martin f. krafft8acd49d2013-08-26 21:22:25 +020043============ ================================================================
44
martin f. krafft1f11ede2013-11-30 16:48:00 +010045Nodes may be defined in subdirectories. However, node names (filename) must be
46unique across all subdirectories, and |reclass| will exit with an error if
47a node is defined multiple times. Subdirectories therefore really only exist
martin f. krafft37b56b62013-12-10 16:04:52 +010048for the administrator's local data structuring. They may be used in mappings
49(see below) to tag additional classes onto nodes.
martin f. krafft1f11ede2013-11-30 16:48:00 +010050
martin f. krafftf4320532013-11-30 17:00:37 +010051Data merging
52------------
53|reclass| has two modes of operation: node information retrieval and inventory
54listing. The second is really just a loop of the first across all defined
55nodes, and needs not be further described.
martin f. krafft8acd49d2013-08-26 21:22:25 +020056
martin f. krafftf4320532013-11-30 17:00:37 +010057When retrieving information about a node, |reclass| first obtains the node
58definition from the storage backend. Then, it iterates the list of classes
59defined for the node and recursively asks the storage backend for each class
60definition (unless already cached).
61
62Next, |reclass| recursively descends each class, looking at the classes it
63defines, and so on, until a leaf node is reached, i.e. a class that references
64no other classes.
65
66Now, the merging starts. At every step, the list of applications and the set
67of parameters at each level is merged into what has been accumulated so far.
68
69Merging of parameters is done "deeply", meaning that lists and dictionaries
martin f. krafft8acd49d2013-08-26 21:22:25 +020070are extended (recursively), rather than replaced. However, a scalar value
71*does* overwrite a dictionary or list value. While the scalar could be
72appended to an existing list, there is sane default assumption in the context
73of a dictionary, so this behaviour seems the most logical.
74
martin f. krafftf4320532013-11-30 17:00:37 +010075After all classes (and the classes they reference) have been visited,
76|reclass| finally merges the applications list and parameters defined for the
77node into what has been accumulated during the processing of the classes, and
78returns the final result.
79
martin f. krafft3b10e802013-11-26 23:30:10 +010080Wildcard/Regexp mappings
81------------------------
82Using the :doc:`configuration file <configfile>`, it is also possible to
83provide a list mappings between node names and classes. For instance::
84
85 class_mappings:
86 - \* default
87 - /^www\d+/ webserver
88 - \*.ch hosted@switzerland another_class_to_show_that_it_can_take_lists
89
90This will assign the ``default`` class to all nodes (make sure to escape
91a leading asterisk (\*) to keep YAML happy), ``webserver`` to all nodes named
92``www1`` or ``www999``, and ``hosted-in-switzerland`` to all nodes whose names
93end with ``.ch`` (again, note the escaped leading asterisk). Multiple classes
94can be assigned to each mapping by providing a space-separated list (class
95names cannot contain spaces anyway).
96
martin f. krafft010ea272013-11-27 14:08:28 +010097.. warning::
98
99 The class mappings do not really belong in the configuration file, as they
100 are data, not configuration inmformation. Therefore, they are likely going
101 to move elsewhere, but I have not quite figured out to where. Most likely,
102 there will be an additional file, specified in the configuration file, which
103 then lists the mappings.
104
martin f. krafft2e233ed2013-11-27 13:50:56 +0100105Note that mappings are not designed to replace node definitions. Mappings can
106be used to pre-populate the classes of existing nodes, but you still need to
107define all nodes (and if only to allow them to be enumerated for the
108inventory).
109
martin f. krafft41521eb2013-11-27 14:06:37 +0100110The mapped classes can also contain backreferences when regular expressions
111are used, although they need to be escaped, e.g.::
112
113 class_mappings:
114 - /\.(\S+)$/ tld-\\1
115
martin f. krafft05cbf6b2013-11-28 13:36:29 +0100116Furthermore, since the outer slashes ('/') are used to "quote" the regular
martin f. krafft37b56b62013-12-10 16:04:52 +0100117expression, *any* slashes within the regular expression must be escaped. For
118instance, the following class mapping assigns a ``subdir-X`` class to all
Daniel Dehennin02550e42013-12-27 09:38:14 +1300119nodes that are defined in a subdirectory (using yaml_fs)::
martin f. krafft05cbf6b2013-11-28 13:36:29 +0100120
121 class_mappings:
martin f. krafft37b56b62013-12-10 16:04:52 +0100122 - /^([^\/]+)\// subdir-\\1
martin f. krafft05cbf6b2013-11-28 13:36:29 +0100123
martin f. krafft8acd49d2013-08-26 21:22:25 +0200124Parameter interpolation
125------------------------
126Parameters may reference each other, including deep references, e.g.::
127
128 parameters:
129 location: Munich, Germany
130 motd:
131 header: This node sits in ${location}
132 for_demonstration: ${motd:header}
133 dict_reference: ${motd}
134
135After merging and interpolation, which happens automatically inside the
136storage modules, the ``for_demonstration`` parameter will have a value of
137"This node sits in Munich, Germany".
138
139Types are preserved if the value contains nothing but a reference. Hence, the
140value of ``dict_reference`` will actually be a dictionary.
141
142You should now be ready to :doc:`use reclass <usage>`!
143
144.. include:: substs.inc