In puppet, we declare every node in manifests/site.pp; give our style guide, this generally means we have something like node <node selector> { role(<puppet role> }, as puppet looks up which classes to apply to a node by node name.
These selectors, while simple in the case of services in small clusters (like, say, the VMs serving lists.wikimedia.org or phabricator) , can become regexes from hell for larger clusters. As a couple examples:
node /^db2(145|146|153|170|174|176|188|203|212|216)\.codfw\./ { role(mariadb::core) } node /^druid10(0[7-9]|1[0-1])\.eqiad\./ { role(druid::public::worker) } node /^elastic(205[5-9]|20[6-9][0-9])\.codfw\./ { role(elasticsearch::cirrus) }
Editing a regexp is truly error prone, and it's not particularly handy. The consequences of a mistake here can be truly dire, even if we can always check what happens using the puppet compiler, there's no reason to do that.
Given the 1:1 correspondence, my proposal is to invert the relationships and declare nodes in such large clusters in a node/data.yaml file, like follows:
mariadb::core: - db2145.codfw.wmnet - db2146.codfw.wmnet ...
and import the definitions in site.pp either via an external node classifier or by running some simple puppet function for the node default declaration to look up in that table.
Allowing this would make it much easier to manage systems that are in large clusters, while we would retain the current system for smaller clusters where it's not convenient.
As a strawman, based on the structure above, would look like:
node default { $fqdn = $facts['networking']['fqdn'] $node_roles = loadyaml('node.yaml').map | String $role, Array $nodes | { $nodes.map | $node | { [$node, $role] } }.reduce({}) | $memo, $value | { # check for collisions $value.each | $v | { if ($v[0] in $memo) { fail("Node ${v[0]} is declared twice, for role ${v[1]} and role ${memo[$v[0]]}") } } $memo + Hash($value) } if $fqdn in $node_roles { role($node_roles[$fqdn]) } }
We can also add CI checks around all this, of course, to make it even safer. We would ofc also need to modify the puppet compiler to make use of such a file in its heuristics, which should work much better as we don't need to "parse" puppet code in python.