Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Error if datadir is not set in hiera.yaml #108

Closed
rwaffen opened this issue Nov 30, 2022 · 4 comments · Fixed by #141
Closed

Error if datadir is not set in hiera.yaml #108

rwaffen opened this issue Nov 30, 2022 · 4 comments · Fixed by #141
Assignees
Labels
bug Something isn't working

Comments

@rwaffen
Copy link
Member

rwaffen commented Nov 30, 2022

is datadir is not set in hiera.yaml, one gets an error in the intrface about datadir being empty/nil.

datadir is not mandatory in hiera.yaml, if not set, it is assumed to be "data".

@rwaffen rwaffen added the bug Something isn't working label Nov 30, 2022
@oneiros
Copy link
Collaborator

oneiros commented Dec 8, 2022

Do you still have the exact error message including the stack trace? And the hiera.yaml you used?

Because this is actually the only place we use code from hiera itself - to get the defaults:

defaults = Puppet::Pops::Lookup::HieraConfigV5::DEFAULT_CONFIG_HASH

And this does in fact include the default for datadir:

> Puppet::Pops::Lookup::HieraConfigV5::DEFAULT_CONFIG_HASH
=> {"version"=>5, "defaults"=>{"datadir"=>"data", "data_hash"=>"yaml_data"}, "hierarchy"=>[{"name"=>"Common", "path"=>"common.yaml"}]}

So in theory this should work. Also in the test data, there is a no_config environment without any custom hiera.yaml at all, that works fine.

So I suspect there is some other factor at play here. Could it be that your hiera.yaml does include a datadir: setting, but without a value?

@tuxmea tuxmea added question Further information is requested and removed bug Something isn't working labels Dec 8, 2022
@tuxmea
Copy link
Member

tuxmea commented Dec 8, 2022

Cross check how hiera.yaml file looks at the customer.

@tuxmea tuxmea closed this as completed Dec 8, 2022
@tuxmea tuxmea reopened this Dec 8, 2022
@tuxmea tuxmea changed the title if datadir is not set in hiera.yaml Error if datadir is not set in hiera.yaml Dec 22, 2022
@tuxmea tuxmea added bug Something isn't working and removed question Further information is requested labels Dec 22, 2022
@tuxmea tuxmea assigned rwaffen and unassigned oneiros Jan 26, 2023
@rwaffen
Copy link
Member Author

rwaffen commented Feb 9, 2023

when datadir is missing in the hiera.yaml the following is in the hdm log

I, [2023-02-09T14:00:48.689078 #24]  INFO -- : [c3985231-dbeb-4516-b3fd-0dcfe2b1e729] Started GET "/environments/production/nodes/puppet.test.priv.rw.betadots.training/keys" for x.x.x.x at 2023-02-09 14:00:48 +0100
I, [2023-02-09T14:00:48.690671 #24]  INFO -- : [c3985231-dbeb-4516-b3fd-0dcfe2b1e729] Processing by KeysController#index as HTML
I, [2023-02-09T14:00:48.690755 #24]  INFO -- : [c3985231-dbeb-4516-b3fd-0dcfe2b1e729]   Parameters: {"environment_id"=>"production", "node_id"=>"puppet.test.priv.rw.betadots.training"}
I, [2023-02-09T14:00:48.816461 #24]  INFO -- : [c3985231-dbeb-4516-b3fd-0dcfe2b1e729] Completed 500 Internal Server Error in 126ms (ActiveRecord: 1.2ms | Allocations: 19599)
F, [2023-02-09T14:00:48.818372 #24] FATAL -- : [c3985231-dbeb-4516-b3fd-0dcfe2b1e729]
[c3985231-dbeb-4516-b3fd-0dcfe2b1e729] TypeError (no implicit conversion of nil into String):
[c3985231-dbeb-4516-b3fd-0dcfe2b1e729]
[c3985231-dbeb-4516-b3fd-0dcfe2b1e729] app/models/hiera_data/hierarchy.rb:35:in `initialize'
[c3985231-dbeb-4516-b3fd-0dcfe2b1e729] app/models/hiera_data/hierarchy.rb:35:in `new'
[c3985231-dbeb-4516-b3fd-0dcfe2b1e729] app/models/hiera_data/hierarchy.rb:35:in `datadir'
[c3985231-dbeb-4516-b3fd-0dcfe2b1e729] app/models/hiera_data.rb:18:in `block (2 levels) in all_keys'
[c3985231-dbeb-4516-b3fd-0dcfe2b1e729] app/models/hiera_data.rb:17:in `each'
[c3985231-dbeb-4516-b3fd-0dcfe2b1e729] app/models/hiera_data.rb:17:in `block in all_keys'
[c3985231-dbeb-4516-b3fd-0dcfe2b1e729] app/models/hiera_data.rb:16:in `each'
[c3985231-dbeb-4516-b3fd-0dcfe2b1e729] app/models/hiera_data.rb:16:in `all_keys'
[c3985231-dbeb-4516-b3fd-0dcfe2b1e729] app/models/key.rb:9:in `all_for'
[c3985231-dbeb-4516-b3fd-0dcfe2b1e729] app/controllers/keys_controller.rb:10:in `index'

hiera.yaml for this scenario:

---
version: 5

defaults:
  lookup_key: eyaml_lookup_key
  options:
    pkcs7_private_key: "/etc/puppetlabs/puppet/keys/private_key.pkcs7.pem"
    pkcs7_public_key: "/etc/puppetlabs/puppet/keys/public_key.pkcs7.pem"

plan_hierarchy:
  - name: "Static data"
    path: "static.yaml"

hierarchy:
  - name: "yaml hierarchy"
    paths:
      - "nodes/%{facts.networking.hostname}.yaml"
      - "role/%{facts.external_facts.role}-%{facts.external_facts.env}.yaml"
      - "role/%{facts.external_facts.role}.yaml"
      - "role/%{trusted.extensions.pp_role}.yaml"
      - "os/%{facts.os.family}.yaml"
      - "zone/%{facts.external_facts.zone}.yaml"

  - name: "Defaults"
    glob: "defaults/*.yaml"

  - name: "Common"
    path: "common.yaml"

@rwaffen rwaffen assigned oneiros and unassigned rwaffen Feb 9, 2023
oneiros added a commit that referenced this issue Feb 10, 2023
Before this, hiera defaults were only used when defaults
were missing altogether from `hiera.yaml`. This changes
that behavior by doing a proper deep merge.
@oneiros
Copy link
Collaborator

oneiros commented Feb 10, 2023

Thank you so much for that backtrace and especially the example configuration. I could now easily reproduce this and the fix was super simple. See #141

rwaffen added a commit that referenced this issue Feb 10, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants