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

Hiera does not merge correctly #426

Closed
jg-development opened this issue Aug 28, 2014 · 8 comments
Closed

Hiera does not merge correctly #426

jg-development opened this issue Aug 28, 2014 · 8 comments

Comments

@jg-development
Copy link
Contributor

I have a hiera file with the following data:

:hierarchy:
    - "%{::environment}"
    - webserver/hosts/foo.local
    - webserver/hosts/bar.local

And 2 yaml files with the following code:

nginx::nginx_vhosts:
  'foo.local:
    ensure: 'present'
    listen_port: '80'
    listen_ip: '*'
    index_files: ['index.php']
    www_root: "/var/www/foo.local"
    server_name: ['foo.local']
    use_default_location: false

and

nginx::nginx_vhosts:
  'bar.local:
    ensure: 'present'
    listen_port: '80'
    listen_ip: '*'
    index_files: ['index.php']
    www_root: "/var/www/bar.local"
    server_name: ['bar.local']
    use_default_location: false

the hiera command " hiera -c hiera.yaml -h nginx::nginx_vhosts"
gives me the correct result... a merge from the two vhosts and files

{"foo.local"=>
  {"ensure"=>"present",
   "listen_port"=>"80",
   "listen_ip"=>"*",
   "index_files"=>["index.php"],
   "www_root"=>"/var/www/foo.local",
   "server_name"=>["foo.local"],
   "use_default_location"=>false},
 "bar.local"=>
  {"ensure"=>"present",
   "listen_port"=>"80",
   "listen_ip"=>"*",
   "index_files"=>["index.php"],
   "www_root"=>"/var/www/bar.local",
   "server_name"=>["bar.local"],
   "use_default_location"=>false}}

But only the first vhost is installed on the system, the second is ignored. I used the multiple files with multiple hashs with other modules and this problem seems to be only with the nginx module.

Greetings Jan

@jg-development
Copy link
Contributor Author

I debugged the output of the hiera_hash in the project:
"hiera_hash('nginx::nginx_vhosts')" results in

{"bar.local"=>{"ensure"=>"present", "listen_port"=>"80", "listen_ip"=>"*"
, "index_files"=>["index.php"], "www_root"=>"/var/www/kdg/www-dev-vbox.kabeldeut
schland.de/ibp", "server_name"=>["bar.local"], "use_d
efault_location"=>false}, "foo.local"=>{"ensure"=>"pr
esent", "listen_port"=>"80", "listen_ip"=>"*", "index_files"=>["index.php"], "ww
w_root"=>"/var/www/kdg/www-dev-vbox.kabeldeutschland.de/ibp", "server_name"=>["s
ervice-dbg-vbox.kabeldeutschland.de"], "use_default_location"=>false}}

but the output from the init.pp with "notice("${nginx_vhosts}")" is

{"foo.local"=>{"ensure"=>"present", "listen_port"=>"80", "listen_ip"=>"*", "index_files"=>
["index.php"], "www_root"=>"/var/www/kdg/www-dev-vbox.kabeldeutschland.de/ibp",
"server_name"=>["foo.local"], "use_default_location"=
>false}}

Does the module gets the informatione before it is fully merged?

@3flex
Copy link
Contributor

3flex commented Aug 28, 2014

Which version of Puppet, Hiera, and the module are you using?

@3flex
Copy link
Contributor

3flex commented Aug 29, 2014

It sounds like you're using Hiera without deep merge support, can you review your settings according to https://docs.puppetlabs.com/hiera/1/lookup_types.html#hash-merge then report back?

@jg-development
Copy link
Contributor Author

I am using hiera 1.3 and native merging.... but didnt native merging should be enough?
The settings with "hiera_hash('nginx::nginx_vhosts')" are working correctly.

@jg-development
Copy link
Contributor Author

The problem apears still with "deeper" merging. However I can reproduce it with another module (puppetlabs/mysql), so I think this maybe a general issue and not something with the nginx module.
Can somebody confirm this?

@jg-development
Copy link
Contributor Author

I close this issue because after deeper investigation it seems to be a hiera/puppet bug

@cp-richard
Copy link

What was the bug (link, etc?)
I am having the same issue and searching got me here.

..update - my issue was with Priority Lookup only for automatic parameter lookup.http://docs.puppetlabs.com/hiera/1/puppet.html#limitations

@dene14
Copy link

dene14 commented May 31, 2015

I did experienced the same issue some time ago, it has became even more confusing when I started to fix "deprecation notice" about direct parameters assignment to class {"nginx":}. So I've done it with a following code in my "nginx_base" profile:

class site::profiles::nginx_base (
$nginx_vhosts = hiera_hash('nginx::nginx_vhosts', {}),
$nginx_upstreams = hiera_hash('nginx::nginx_upstreams', {}),
$nginx_locations = hiera_hash('nginx::nginx_locations', {}),
$http_cfg_append = hiera_hash('nginx::config::http_cfg_append', {}),
) {

############### Some magic to autoconfigure collect::plugin::nginx ###############
$status_location = "${nginx_locations['stub_status']['location']}"
$status_vhost = "${nginx_locations['stub_status']['vhost']}"
$status_hostname = "${nginx_vhosts[$status_vhost]['server_name'][0]}"
$status_port = "${nginx_vhosts[$status_vhost]['listen_port']}"
$status_url = "http://${status_hostname}:${status_port}${status_location}"
##################################################################################

class {'nginx::config':
http_cfg_append => $http_cfg_append,
# expand by parameters which require hash's deep merge
}

class {'nginx':
nginx_vhosts => $nginx_vhosts,
nginx_upstreams => $nginx_upstreams,
nginx_locations => $nginx_locations,
# expand by parameters which require hash's deep merge
}
->
class { 'collectd::plugin::nginx':
url => "$status_url"
}
->
Class['site::profiles::nginx_base']
}

You can adjust hiera lookups as needed (for priority lookups). However, I'd like to hear some notes from maintainers whether I did it right or wrong.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants