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

Please add a 'warn' when someone is using 'nginx::resource::vhost' without previously including the nginx class #983

Closed
law opened this issue Dec 8, 2016 · 1 comment
Labels
bug Something isn't working

Comments

@law
Copy link

law commented Dec 8, 2016

Affected Puppet, Ruby, OS and module versions/distributions

  • Puppet: 4.x
  • Ruby: 2.3.x
  • Distribution: Ubuntu
  • Module version: 0.5.0

How to reproduce (e.g Puppet code you use)

Given Hiera data like:

role::web::myhost_nginx_vhosts:
  'somehost.mycorp.lan':
    www_root: '/var/www'
    listen_options: 'default_server'
    server_name: ["%{networking.fqdn}"]
    access_log: '/var/log/nginx/myhost-access.log'
    error_log: '/var/log/nginx/myhost-error.log'

and instantiating it in a far-flung role with

class role::web ($myhost_nginx_vhosts) {
  create_resources('nginx::resource::vhost', $myhost_nginx_vhosts)
} 

there will be failures along the lines of:
Evaluation Error: Error while evaluating a Function Call, nil is not an Array. It looks to be a NilClass at /etc/puppetlabs/code/environments/vagrant/modules/nginx/manifests/resource/vhost.pp:407:3 at /etc/puppetlabs/code/environments/vagrant/modules/role/manifests/web.pp:1 on node blasrgh
This provides few hints as to the root cause of the error, which in this case is our hapless hero forgot to put:
class { 'nginx': }

in the role, kicking off three days of hair-pulling debugging, swearing, and kicking things. Total PEBKAC, yes, but having
unless defined('class nginx { warn('You might want to consider including the nginx class if you are getting strange evaluation errors') }

would've been MOST helpful.

What are you seeing

Red. Mainly from my own foibles.

What behaviour did you expect instead

I expected the module to compile without complaint, but I would've settled for a warning informing me the 'nginx' parent class was not included when I tried to use the vhost defined-type.

Output log

Any additional information you'd like to impart

@vinzent vinzent added the bug Something isn't working label Apr 11, 2017
@vinzent
Copy link
Contributor

vinzent commented Apr 11, 2017

I think it should not only warn it should fail. the defined type wants to read defaults from the ::ngninx class - which it only can if it is already parsed. the only way to ensure this is to explicitly include it before defining a resource.

cegeka-jenkins pushed a commit to cegeka/puppet-nginx that referenced this issue Sep 13, 2019
Because the `ngnix::resource:*` types access ::ngnix class
parameters the nginx class needs to be declared before calling
the defined type.

`include ::nginx` inside the defined type is not enough because
params are evaluated before include is parsed.

Two of the defined types only access params inside. The include
way would work there - but for consistency I also added the fail.

Closes voxpupuli#983
Rubueno pushed a commit to Rubueno/puppet-nginx that referenced this issue Oct 19, 2020
Because the `ngnix::resource:*` types access ::ngnix class
parameters the nginx class needs to be declared before calling
the defined type.

`include ::nginx` inside the defined type is not enough because
params are evaluated before include is parsed.

Two of the defined types only access params inside. The include
way would work there - but for consistency I also added the fail.

Closes voxpupuli#983
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

No branches or pull requests

2 participants