| The above could be turned into a "key mapper" function. A user of the function would specify "path" to a data file, and the data file would contain the key mapping:
--- |
hostgroup_specific_root_password: %{facts.hostgroup}_root_password'
|
The function would read the data file given to the function in options[path], using a read_yaml function. It can then cache this result using the $context cache methods. On a lookup, it gets the data from the cache, if the key being looked up is present (e.g. 'hostgroup_specific_root_password'), it gets the value and calls $context.interpolate to interpolate it. This forms the new key, which it then uses in a call to lookup - the returned value from lookup is returned from the function. This generalized version would only be a couple of lines longer than the first example. |