bernd / fpm-cookery

A tool for building software packages with fpm.
Other
460 stars 88 forks source link

Hiera failure on incorrect file extension. #174

Open lordnynex opened 7 years ago

lordnynex commented 7 years ago

Hello,

Just spent a fair bit of time chasing an obscure exception (filing in a separate issue). It appears the code is looking for a default 'common.yaml' (emphasis on yAml). It's pretty common to abbreviate .yaml to .yml. May be a good feature to detect the alternate condensed .yml extension.

tomeon commented 7 years ago

@lordnynex -- unfortunately this is a shortcoming of Hiera itself.

Here's Hiera::Backend.datasourcefiles

def datasourcefiles(backend, scope, extension, override=nil, hierarchy=nil)
  datadir = Backend.datadir(backend, scope)
  Backend.datasources(scope, override, hierarchy) do |source|
    Hiera.debug("Looking for data source #{source}")
    file = datafile_in(datadir, source, extension)

    if file
      yield source, file
    end
  end
end

And here's Hiera::Backend::Yaml_backend

Backend.datasourcefiles(:yaml, scope, "yaml", order_override) do |source, yamlfile|

Because the YAML backend hardcodes "yaml" as the argument bound to extension, the only way for us to override it is to subclass Hiera::Backend::Yaml_backend and invoke datasourcefiles with "yml" as well. This is probably overkill, but maybe we should at least warn users about the issue.