puppet-nginx
puppet-nginx copied to clipboard
log_dir not respected from Hiera
When I set log_dir
using Hiera, that directory is not being respected, and instead the default directory of /var/log/nginx
is used.
Affected Puppet, Ruby, OS and module versions/distributions
- Puppet: 3.7
- Ruby: 2.1.5
- Distribution: Ubuntu
- Module version: 0.6.0
How to reproduce (e.g Puppet code you use)
Hiera:
nginx::log_dir: '/mnt/logs'
What are you seeing
Server files that are written by Puppet have /var/log
for the access and error logs in them.
What behaviour did you expect instead
I expect log paths to have /mnt/logs
at the start.
Any additional information you'd like to impart
I suspect that this is due to the way that Puppet looks up parameters. The parameters http_access_log
and http_error_log
use log_dir
, i.e., http_access_log => "${log_dir}/${::nginx::params::http_access_log_file}"
. I suspect that in that context, log_dir
is the default, and not the one that I have provided in Hiera.
It works for me. If I don't set the parameter, all logs go to /var/log/nginx/
for each of my server blocks. If I set the nginx::log_dir
value, all the access_log and error_log directives in all my server blocks use this value instead of /var/log/nginx/
. I personnaly use the nginx package from RHEL 7 Software Collections and its default log dir is /var/opt/rh/rh-nginx18/log/nginx/
and I use the nginx::log_dir
parameter to set it. If you want to set the global log dirs, though, you need to use these parameters:
nginx::http_access_log: '/var/opt/rh/rh-nginx18/log/nginx/access.log'
nginx::nginx_error_log: '/var/opt/rh/rh-nginx18/log/nginx/error.log'
Maybe it's a Puppet 3 thing. Which version of Puppet are you using?
3.6
Are you setting it in Hiera?
It works if I explicitly do this:
class { '::nginx':
log_dir => hiera('nginx::log_dir'),
}
But if I have it set in Hiera and just do include nginx
, then it doesn't use the one I set.
Here's what I originally had:
class profile::rpnginx {
class { 'nginx': }
}
I changed it to include nginx
and a puppet run changes nothing.
In both cases if I change this:
nginx::log_dir: '/var/opt/rh/rh-nginx18/log/nginx'
to
nginx::log_dir: '/var/opt/rh/rh-nginx18/log/nginx2'
a puppet noop run tells me that it would change the access and error logs path for all my servers (vhosts).
Can you run this on your puppet master:
hiera nginx::log_dir fqdn=server.example.com --debug
Yes, I set nginx::log_dir:
in hiera.
# hiera -c /etc/puppet/hiera.yaml nginx::log_dir fqdn=server.example.com --debug
DEBUG: 2017-02-23 08:12:46 -0500: Hiera YAML backend starting
DEBUG: 2017-02-23 08:12:46 -0500: Looking up nginx::log_dir in YAML backend
DEBUG: 2017-02-23 08:12:46 -0500: Looking for data source host/aserver.example.com
DEBUG: 2017-02-23 08:12:46 -0500: Found nginx::log_dir in host/server.example.com
/var/opt/rh/rh-nginx18/log/nginx
We don't have puppet masters. On the node:
/etc/puppet$ bin/hiera -c hiera.yaml nginx::log_dir --debug
DEBUG: 2017-02-23 17:39:02 -0500: Hiera YAML backend starting
DEBUG: 2017-02-23 17:39:02 -0500: Looking up nginx::log_dir in YAML backend
DEBUG: 2017-02-23 17:39:02 -0500: Looking for data source common
DEBUG: 2017-02-23 17:39:02 -0500: Found nginx::log_dir in common
/mnt/logs/nginx
I'll try to make a test case to reproduce this.
You're setting log_dir in common.yaml? So all your servers have this parameter set?
Have you tried with the current master, just in case? Did you try running puppet apply with --debug just to make sure you didn't miss an error?
Yes we have it set in our top level Hiera file. All the hosts I have checked on have the wrong path set in the generated files.
I just migrated our code to v0.6.0 and was having this problem with several hosts. I think I had the same problem on v0.5.0 but didn't realise that it was the problem at the time.
What sort of errors would I be looking for? If Puppet succeeded then why would there be any other errors?
I don't know... I find hiera especially hard to troubleshoot. Can you give us more details? (Full hiera configs, full generated file example)
Just noticed something playing around. It is only in nginx.conf
that there is a problem. The servers all have the correct path.
The configs in nginx.conf are different than servers'. Check my first comment in this issue.
Ok that makes sense now. This seems like a bug to me. Setting nginx::log_dir
should be enough, and in fact it is enough when you set it through Puppet. So the bug is that when set through Hiera it doesn't work.