Using a vhost name in hiera

54 views
Skip to first unread message

Ugo Bellavance

unread,
Sep 28, 2016, 3:54:15 PM9/28/16
to Puppet Users
Hi,

I am working with this module https://github.com/voxpupuli/puppet-nginx to get some nginx servers up.  Here is my hiera config for a vhost:

nginx::nginx_vhosts:

I would like to have my logs in one directory per vhost.

Here is what I have for now:

nginx::http_access_log: "%{hiera('nginx::config::log_dir')}/access_log"


In the template, it looks like that:

"${::nginx::config::log_dir}/${name_sanitized}.access.log ${format_log}",

Would there be a way to set it in hiera so that it is the equivalent of this:

"${::nginx::config::log_dir}/${name_sanitized}/access.log ${format_log}",

Of course, I would like to avoid having to edit the template.

Thanks,

Garrett Honeycutt

unread,
Sep 28, 2016, 4:35:50 PM9/28/16
to puppet...@googlegroups.com
Hi Ugo,

nginx_vhosts has a parameter named access_log. You could use that as
follows.

nginx::nginx_vhosts:
'website1.domain.com':
proxy: 'http://website1.internal'
access_log: '/whatever/access.log'

https://github.com/voxpupuli/puppet-nginx/blob/master/manifests/resource/vhost.pp#L145

Best regards,
-g

--
Garrett Honeycutt
@learnpuppet
Puppet Training with LearnPuppet.com
Mobile: +1.206.414.8658

Ugo Bellavance

unread,
Sep 28, 2016, 8:07:26 PM9/28/16
to Puppet Users
Makes sense, I didn't see that one. In fact I was looking for a way to make it automatic instead of always have to enter the log path.

Thanks, 

Ugo Bellavance

unread,
Sep 29, 2016, 9:52:40 AM9/29/16
to Puppet Users
I tested it but the system complains that the directory doesn't exist.  I wonder how I could easily create a folder for each vhost, and I don't know how it could be managed automatially in the module since puppet doesn't create parent directories for File directives.  It looks like I'll have to stick to the default.

That makes me think of something.  Could I enumerate the names of all my vhosts in hiera, and have only one vhost directive?  Something like here https://blog.serverdensity.com/deploying-nginx-with-puppet/ but with something like a table of vdomain values.

It looks very hard to find relevant information on how to use hiera... but it is such an excellent tool!

Garrett Honeycutt

unread,
Sep 29, 2016, 9:59:49 AM9/29/16
to puppet...@googlegroups.com
On 9/29/16 9:52 AM, Ugo Bellavance wrote:
>
>
> On Wednesday, September 28, 2016 at 8:07:26 PM UTC-4, Ugo Bellavance wrote:
>
>
>
> On Wednesday, September 28, 2016 at 4:35:50 PM UTC-4, Garrett
> Honeycutt wrote:
>
> On 9/28/16 3:54 PM, Ugo Bellavance wrote:
> > Hi,
> >
> > I am working with this module
> https://github.com/voxpupuli/puppet-nginx
> <https://github.com/voxpupuli/puppet-nginx>
> > to get some nginx servers up. Here is my hiera config for a
> vhost:
> >
> > nginx::nginx_vhosts:
> > 'website1.domain.com <http://website1.domain.com>':
> > proxy: 'http://website1.internal'
> >
> > I would like to have my logs in one directory per vhost.
> >
> > Here is what I have for now:
> >
> > nginx::http_access_log:
> "%{hiera('nginx::config::log_dir')}/access_log"
> >
> >
> > In the template, it looks like that:
> >
> > "${::nginx::config::log_dir}/${name_sanitized}.access.log
> ${format_log}",
> >
> > Would there be a way to set it in hiera so that it is the
> equivalent of
> > this:
> >
> > "${::nginx::config::log_dir}/${name_sanitized}/access.log
> ${format_log}",
> >
> > Of course, I would like to avoid having to edit the template.
> >
> > Thanks,
> >
>
> Hi Ugo,
>
> nginx_vhosts has a parameter named access_log. You could use
> that as
> follows.
>
> nginx::nginx_vhosts:
> 'website1.domain.com <http://website1.domain.com>':
> proxy: 'http://website1.internal'
> access_log: '/whatever/access.log'
>
> https://github.com/voxpupuli/puppet-nginx/blob/master/manifests/resource/vhost.pp#L145
> <https://github.com/voxpupuli/puppet-nginx/blob/master/manifests/resource/vhost.pp#L145>
>
>
>
> Makes sense, I didn't see that one. In fact I was looking for a way
> to make it automatic instead of always have to enter the log path.
>
>
> I tested it but the system complains that the directory doesn't exist.
> I wonder how I could easily create a folder for each vhost, and I don't
> know how it could be managed automatially in the module since puppet
> doesn't create parent directories for File directives. It looks like
> I'll have to stick to the default.
>
> That makes me think of something. Could I enumerate the names of all my
> vhosts in hiera, and have only one vhost directive? Something like
> here https://blog.serverdensity.com/deploying-nginx-with-puppet/ but
> with something like a table of vdomain values.
>
> It looks very hard to find relevant information on how to use hiera...
> but it is such an excellent tool!
>

Hi Ugo,

Suggest creating a profile class that includes nginx as well as ensuring
that all those directories exist first.

An alternative would be to send a pull request to the nginx module that
runs `mkdir -p` for you when specifying a custom access_log.
Reply all
Reply to author
Forward
0 new messages