voxpupuli / puppet-nginx

Puppet Module to manage NGINX on various UNIXes
https://forge.puppet.com/puppet/nginx
MIT License
471 stars 882 forks source link

How to use Hiera? #836

Open davividal opened 8 years ago

davividal commented 8 years ago

I'm writing a custom module to get jenkins up and running. Jenkins is fine, but I'm trying to setup nginx using hiera. Here is my data/common.yaml:


---
nginx::nginx_upstreams:
  'jenkins':
    ensure: present
    members:
      - localhost:9000
nginx::nginx_vhosts:
  'jenkins.local':
    ssl: true
    proxy: 'http://jenkins'

My metadata.json:

{
  "author": "Davi Koscianski Vidal",
  "dependencies": [
    {"name":"jfryman/nginx", "version_requirement":">=0.3.0 < 1.0.0"}
  ],
  "license": "",
  "name": "davividal-jenkins",
  "operatingsystem_support": [],
  "project_page": "",
  "requirements": [],
  "source": "",
  "summary": "",
  "tags": [],
  "version": "0.1.0",
  "data_provider": "hiera"
}

Should I put anything other than class { 'nginx': } on my init.pp? EDIT: I also tried both include nginx and include ::nginx, without success.

davividal commented 8 years ago

FWIW, I'm using Puppet 4

jlintz commented 8 years ago

What errors are you getting? I'm doing something similar without any issues

davividal commented 8 years ago

@jlintz I'm getting no errors. It simply does not work. I asked around at #puppet , and it looks like this doesn't work.

jlintz commented 8 years ago

can you verify with hiera cmdline that you are able to read the values as expected from hiera?

davividal commented 8 years ago

@jlintz I'm not sure as to how to do that. Can you point me to any doc?

jlintz commented 8 years ago

Take a look at https://docs.puppet.com/hiera/3.2/command_line.html

ubellavance commented 8 years ago

I realized that there are many things that must be configured properly for hiera to work. Still looks like black magic for me. One thing that would help would be to see your hiera.yaml file. Also, did you put

classes:
  - nginx

at the top of your common.yaml?

Where is data/common.yaml?

ubellavance commented 8 years ago

Also try something like this:

hiera -c /etc/puppet/hiera.yaml nginx::nginx_vhosts fqdn=server.domain.com --debug

and post the output.

rnelson0 commented 8 years ago

@davividal Please be more specific with what does and does not work. Is the nginx class not being included at all, or is it being included with the defaults but not the settings from hiera? Those two problems and significantly different and knowing exactly what is happening would help us a lot.

Also, you could add a gist (gist.github.com) with additional files so your hiera, site manifests, etc. are all in one place. That might be easiest to reference and comment on.

davividal commented 8 years ago

@rnelson0 this is what I'm trying to accomplish: https://github.com/davividal/rcjenkins . On my node I'm simply running puppet agent -t -v. I'm sure that hiera is working because my modules' vars are being properly assigned.

I tried @ubellavance suggestion on https://github.com/davividal/rcjenkins/blob/master/data/common.yaml, without success.

Please let me know if I wasn't clear enough.

davividal commented 8 years ago

Also:

# hiera -c /etc/puppetlabs/puppet/hiera.yaml nginx::nginx_vhosts fqdn=ip-192-168-1-156.sa-east-1.compute.internal environment=stage --debug 
DEBUG: 2016-09-28 17:22:54 -0300: Hiera YAML backend starting
DEBUG: 2016-09-28 17:22:54 -0300: Looking up nginx::nginx_vhosts in YAML backend
DEBUG: 2016-09-28 17:22:54 -0300: Looking for data source common
nil
ubellavance commented 8 years ago

Can we see the contents of /etc/puppetlabs/puppet/hiera.yaml? And, if possible, where you define the nginx_vhosts configs for this host. You could try removing the environment in your command.

davividal commented 8 years ago

@ubellavance : nginx::nginx_vhosts: https://github.com/davividal/rcjenkins/blob/master/data/common.yaml

/etc/puppetlabs/puppet/hiera.yaml:

---
:backends:
  - yaml
:hierarchy:
  - "nodes/%{::trusted.certname}"
  - common

:yaml:
# datadir is empty here, so hiera uses its defaults:
# - /etc/puppetlabs/code/environments/%{environment}/hieradata on *nix
# - %CommonAppData%\PuppetLabs\code\environments\%{environment}\hieradata on Windows
# When specifying a datadir, make sure the directory exists.
  :datadir:
ubellavance commented 8 years ago

It is different from what I can see in your git repo... Have you tried setting the datadir value? Not sure about this one but the rest looks OK. Have you tried adding this to your common.yaml:

classes:
  - nginx
ubellavance commented 8 years ago

And if you've changed your hiera config, it may be necessary to restart your puppet master.

davividal commented 8 years ago

It is different from the hiera.yaml from the git repo because that is the module's hiera.yaml. The one I posted is the hiera from my puppet master.

I've tried adding classes: [nginx] without success.

ubellavance commented 8 years ago

I suggested

classes:
  - nginx

Not

classes: [nginx]

but I don't know if there is a real difference. Have you tried to make anything else work with hiera? Maybe try the ntp module, which is used in the puppetlabs hiera doc as an example. Did you restart your puppet master?

davividal commented 8 years ago

@ubellavance there is no difference. :) And, in fact, I tried exactly what you suggested, I was just lazy to write it all. Since I was only dealing with modules, I didn't restart my puppet master.

ubellavance commented 8 years ago

Ok sorry but that's about as far as I can go with my little puppet/hiera knowledge. You may want to try a puppetlabs module like ntp, try to make it work with hiera and post on the puppet group for help if it doesn't work.

ffrank commented 7 years ago

FWIW, the nginx::nginx_upstreams should work. nginx::nginx_vhosts is probably ignored because the parameter is actually called $nginx_servers, so you'll need the Hiera key nginx::nginx_servers.

For debugging:

  1. Put a notify { "debug": message => hiera("nginx::nginx_servers") next to your include ::nginx. (Prefer include over class { '::nginx': } in general.)
  2. Temporarily modify the copy of the module on your master and add a notify { "debug2": message => $nginx_servers } in the body of the nginx class.

Those should give you an indication whether the values are being loaded and used okay.

wyardley commented 7 years ago

@ffrank: It's only nginx_servers if he's using current or recent git version. The big vhost => server rename hasn't been released yet.

ffrank commented 7 years ago

😭

Well apart from that mixup, I do at least stand by my recommendations, minus the re-rename of the parameter 😅