This module takes a FQDN as input and returns the contents of the matching YAML file.
This is intended to be used as an External Node Classifier with Puppet. It is invoked with the FQDN of the node as the first positional parameter given to the binary. Bun then returns the contents of the YAML file which matches that given FQDN.
It finds the file by splitting the FQDN on . and -, joining the tokens with -, and then removing each token from right to left until it finds a matching file name.
So for example, given the node name of test-server.example.com, bun is invoked with bun test-server.example.com. Bun will split the FQDN to become @["test", "server", "example", "com"]. This is then joined together with hyphens - and the following file paths tested.
- /etc/puppetlabs/puppet/bun.nim/nodes/test-server-example-com.yaml - /etc/puppetlabs/puppet/bun.nim/nodes/test-server-example.yaml - /etc/puppetlabs/puppet/bun.nim/nodes/test-server.yaml - /etc/puppetlabs/puppet/bun.nim/nodes/test.yaml
Each of those file paths are tested in turn until bun finds an existing file and returns its contents. Otherwise, the contents of the default.yaml file is returned.
Procs
proc getTokens(fqdn: string): seq[string] {...}{.raises: [], tags: [].}
- Splits the FQDN into tokens. Splits on . and -. Most server names use both periods and hyphens, for example, test-server.example.com. This would be split into @["test", "server", "example", "com"]
proc findMatch(tokens: seq[string]): string {...}{.raises: [], tags: [ReadDirEffect].}
-
Iterates over the tokens to find the first matching file. Works from right to left, so @["test", "server", "example", "com"] looks for the following files in order:
- test-server-example-com.yaml - test-server-example.yaml - test-server.yaml - test.yaml
If a file isnt found, it instead returns default.yaml