voxpupuli / puppet-elasticsearch

Elasticsearch Puppet module
Apache License 2.0
404 stars 476 forks source link

Version 6.x.x does not work with Puppet 4 #955

Closed Programie closed 5 years ago

Programie commented 6 years ago

Bug description

The puppet run fails with the following error:

Error while evaluating a Resource Statement, undefined method `pop' for nil:NilClass at /etc/puppetlabs/code/environments/<myenvironment>/nodes/mynode.pp:2:3 on node mynode

Stacktrace shown on the Puppet Master:

/opt/puppetlabs/puppet/lib/ruby/vendor_ruby/puppet/pops/lookup/invocation.rb:79:in `with'
/opt/puppetlabs/puppet/lib/ruby/vendor_ruby/puppet/data_providers/lookup_adapter.rb:149:in `do_lookup'
/opt/puppetlabs/puppet/lib/ruby/vendor_ruby/puppet/data_providers/lookup_adapter.rb:72:in `lookup'
/opt/puppetlabs/puppet/lib/ruby/vendor_ruby/puppet/pops/lookup.rb:77:in `search_and_merge'
/opt/puppetlabs/puppet/lib/ruby/vendor_ruby/puppet/resource/type.rb:401:in `inject_external_parameters'
org/jruby/RubyKernel.java:1242:in `catch'
/opt/puppetlabs/puppet/lib/ruby/vendor_ruby/puppet/resource/type.rb:400:in `inject_external_parameters'
org/jruby/RubyHash.java:1342:in `each'
/opt/puppetlabs/puppet/lib/ruby/vendor_ruby/puppet/resource/type.rb:396:in `inject_external_parameters'
/opt/puppetlabs/puppet/lib/ruby/vendor_ruby/puppet/resource/type.rb:363:in `set_resource_parameters'
/opt/puppetlabs/puppet/lib/ruby/vendor_ruby/puppet/resource/type.rb:171:in `evaluate_code'
/opt/puppetlabs/puppet/lib/ruby/vendor_ruby/puppet/parser/resource.rb:81:in `evaluate'
/opt/puppetlabs/puppet/lib/ruby/vendor_ruby/puppet/util/profiler/around_profiler.rb:58:in `profile'
/opt/puppetlabs/puppet/lib/ruby/vendor_ruby/puppet/util/profiler.rb:51:in `profile'
/opt/puppetlabs/puppet/lib/ruby/vendor_ruby/puppet/parser/resource.rb:73:in `evaluate'
org/jruby/RubyArray.java:1613:in `each'
/opt/puppetlabs/puppet/lib/ruby/vendor_ruby/puppet/parser/compiler.rb:395:in `evaluate_classes'
/opt/puppetlabs/puppet/lib/ruby/vendor_ruby/puppet/pops/evaluator/runtime3_resource_support.rb:61:in `create_resources'
org/jruby/RubyArray.java:2414:in `map'
/opt/puppetlabs/puppet/lib/ruby/vendor_ruby/puppet/pops/evaluator/runtime3_resource_support.rb:37:in `create_resources'
/opt/puppetlabs/puppet/lib/ruby/vendor_ruby/puppet/pops/evaluator/runtime3_support.rb:321:in `create_resources'
/opt/puppetlabs/puppet/lib/ruby/vendor_ruby/puppet/pops/evaluator/evaluator_impl.rb:842:in `eval_ResourceExpression'
org/jruby/RubyArray.java:2414:in `map'
/opt/puppetlabs/puppet/lib/ruby/vendor_ruby/puppet/pops/evaluator/evaluator_impl.rb:839:in `eval_ResourceExpression'
/opt/puppetlabs/puppet/lib/ruby/vendor_ruby/puppet/pops/visitor.rb:69:in `visit_this_1'
/opt/puppetlabs/puppet/lib/ruby/vendor_ruby/puppet/pops/evaluator/evaluator_impl.rb:82:in `evaluate'
/opt/puppetlabs/puppet/lib/ruby/vendor_ruby/puppet/pops/evaluator/evaluator_impl.rb:638:in `eval_BlockExpression'
org/jruby/RubyArray.java:1613:in `each'
org/jruby/RubyEnumerable.java:852:in `inject'
/opt/puppetlabs/puppet/lib/ruby/vendor_ruby/puppet/pops/evaluator/evaluator_impl.rb:638:in `eval_BlockExpression'
/opt/puppetlabs/puppet/lib/ruby/vendor_ruby/puppet/pops/visitor.rb:69:in `visit_this_1'
/opt/puppetlabs/puppet/lib/ruby/vendor_ruby/puppet/pops/evaluator/evaluator_impl.rb:82:in `evaluate'
/opt/puppetlabs/puppet/lib/ruby/vendor_ruby/puppet/pops/parser/evaluating_parser.rb:63:in `evaluate'
/opt/puppetlabs/puppet/lib/ruby/vendor_ruby/puppet/parser/ast/pops_bridge.rb:32:in `evaluate'
/opt/puppetlabs/puppet/lib/ruby/vendor_ruby/puppet/parser/ast/pops_bridge.rb:72:in `evaluate'
org/jruby/RubyKernel.java:1242:in `catch'
/opt/puppetlabs/puppet/lib/ruby/vendor_ruby/puppet/parser/ast/pops_bridge.rb:71:in `evaluate'
org/jruby/RubyKernel.java:1242:in `catch'
/opt/puppetlabs/puppet/lib/ruby/vendor_ruby/puppet/parser/ast/pops_bridge.rb:70:in `evaluate'
/opt/puppetlabs/puppet/lib/ruby/vendor_ruby/puppet/parser/ast.rb:31:in `safeevaluate'
/opt/puppetlabs/puppet/lib/ruby/vendor_ruby/puppet/resource/type.rb:184:in `evaluate_code'
/opt/puppetlabs/puppet/lib/ruby/vendor_ruby/puppet/parser/resource.rb:81:in `evaluate'
/opt/puppetlabs/puppet/lib/ruby/vendor_ruby/puppet/util/profiler/around_profiler.rb:58:in `profile'
/opt/puppetlabs/puppet/lib/ruby/vendor_ruby/puppet/util/profiler.rb:51:in `profile'
/opt/puppetlabs/puppet/lib/ruby/vendor_ruby/puppet/parser/resource.rb:73:in `evaluate'
org/jruby/RubyArray.java:1613:in `each'
/opt/puppetlabs/puppet/lib/ruby/vendor_ruby/puppet/parser/compiler.rb:395:in `evaluate_classes'
/opt/puppetlabs/puppet/lib/ruby/vendor_ruby/puppet/pops/evaluator/runtime3_resource_support.rb:61:in `create_resources'
org/jruby/RubyArray.java:2414:in `map'
/opt/puppetlabs/puppet/lib/ruby/vendor_ruby/puppet/pops/evaluator/runtime3_resource_support.rb:37:in `create_resources'
/opt/puppetlabs/puppet/lib/ruby/vendor_ruby/puppet/pops/evaluator/runtime3_support.rb:321:in `create_resources'
/opt/puppetlabs/puppet/lib/ruby/vendor_ruby/puppet/pops/evaluator/evaluator_impl.rb:842:in `eval_ResourceExpression'
org/jruby/RubyArray.java:2414:in `map'
/opt/puppetlabs/puppet/lib/ruby/vendor_ruby/puppet/pops/evaluator/evaluator_impl.rb:839:in `eval_ResourceExpression'
/opt/puppetlabs/puppet/lib/ruby/vendor_ruby/puppet/pops/visitor.rb:69:in `visit_this_1'
/opt/puppetlabs/puppet/lib/ruby/vendor_ruby/puppet/pops/evaluator/evaluator_impl.rb:82:in `evaluate'
/opt/puppetlabs/puppet/lib/ruby/vendor_ruby/puppet/pops/evaluator/evaluator_impl.rb:638:in `eval_BlockExpression'
org/jruby/RubyArray.java:1613:in `each'
org/jruby/RubyEnumerable.java:852:in `inject'
/opt/puppetlabs/puppet/lib/ruby/vendor_ruby/puppet/pops/evaluator/evaluator_impl.rb:638:in `eval_BlockExpression'
/opt/puppetlabs/puppet/lib/ruby/vendor_ruby/puppet/pops/visitor.rb:69:in `visit_this_1'
/opt/puppetlabs/puppet/lib/ruby/vendor_ruby/puppet/pops/evaluator/evaluator_impl.rb:82:in `evaluate'
/opt/puppetlabs/puppet/lib/ruby/vendor_ruby/puppet/pops/parser/evaluating_parser.rb:63:in `evaluate'
/opt/puppetlabs/puppet/lib/ruby/vendor_ruby/puppet/parser/ast/pops_bridge.rb:32:in `evaluate'
/opt/puppetlabs/puppet/lib/ruby/vendor_ruby/puppet/parser/ast.rb:31:in `safeevaluate'
/opt/puppetlabs/puppet/lib/ruby/vendor_ruby/puppet/resource/type.rb:181:in `evaluate_code'
/opt/puppetlabs/puppet/lib/ruby/vendor_ruby/puppet/parser/scope.rb:944:in `with_guarded_scope'
/opt/puppetlabs/puppet/lib/ruby/vendor_ruby/puppet/resource/type.rb:179:in `evaluate_code'
/opt/puppetlabs/puppet/lib/ruby/vendor_ruby/puppet/parser/resource.rb:81:in `evaluate'
/opt/puppetlabs/puppet/lib/ruby/vendor_ruby/puppet/util/profiler/around_profiler.rb:58:in `profile'
/opt/puppetlabs/puppet/lib/ruby/vendor_ruby/puppet/util/profiler.rb:51:in `profile'
/opt/puppetlabs/puppet/lib/ruby/vendor_ruby/puppet/parser/resource.rb:73:in `evaluate'
/opt/puppetlabs/puppet/lib/ruby/vendor_ruby/puppet/parser/compiler.rb:555:in `evaluate_ast_node'
/opt/puppetlabs/puppet/lib/ruby/vendor_ruby/puppet/parser/compiler.rb:178:in `compile'
/opt/puppetlabs/puppet/lib/ruby/vendor_ruby/puppet/util/profiler/around_profiler.rb:58:in `profile'
/opt/puppetlabs/puppet/lib/ruby/vendor_ruby/puppet/util/profiler.rb:51:in `profile'
/opt/puppetlabs/puppet/lib/ruby/vendor_ruby/puppet/parser/compiler.rb:178:in `compile'
/opt/puppetlabs/puppet/lib/ruby/vendor_ruby/puppet/context.rb:65:in `override'
/opt/puppetlabs/puppet/lib/ruby/vendor_ruby/puppet.rb:241:in `override'
/opt/puppetlabs/puppet/lib/ruby/vendor_ruby/puppet/parser/compiler.rb:162:in `compile'
/opt/puppetlabs/puppet/lib/ruby/vendor_ruby/puppet/parser/compiler.rb:33:in `compile'
/opt/puppetlabs/puppet/lib/ruby/vendor_ruby/puppet/indirector/catalog/compiler.rb:266:in `compile'
/opt/puppetlabs/puppet/lib/ruby/vendor_ruby/puppet/util/profiler/around_profiler.rb:58:in `profile'
/opt/puppetlabs/puppet/lib/ruby/vendor_ruby/puppet/util/profiler.rb:51:in `profile'
/opt/puppetlabs/puppet/lib/ruby/vendor_ruby/puppet/indirector/catalog/compiler.rb:264:in `compile'
/opt/puppetlabs/puppet/lib/ruby/vendor_ruby/puppet/util.rb:223:in `benchmark'
/opt/puppetlabs/server/apps/puppetserver/puppet-server-release.jar!/META-INF/jruby.home/lib/ruby/1.9/benchmark.rb:295:in `realtime'
/opt/puppetlabs/puppet/lib/ruby/vendor_ruby/puppet/util.rb:222:in `benchmark'
/opt/puppetlabs/puppet/lib/ruby/vendor_ruby/puppet/indirector/catalog/compiler.rb:262:in `compile'
/opt/puppetlabs/puppet/lib/ruby/vendor_ruby/puppet/indirector/catalog/compiler.rb:53:in `find'
/opt/puppetlabs/puppet/lib/ruby/vendor_ruby/puppet/indirector/indirection.rb:194:in `find'
/opt/puppetlabs/puppet/lib/ruby/vendor_ruby/puppet/network/http/api/indirected_routes.rb:121:in `do_find'
/opt/puppetlabs/puppet/lib/ruby/vendor_ruby/puppet/network/http/api/indirected_routes.rb:48:in `call'
/opt/puppetlabs/puppet/lib/ruby/vendor_ruby/puppet/context.rb:65:in `override'
/opt/puppetlabs/puppet/lib/ruby/vendor_ruby/puppet.rb:241:in `override'
/opt/puppetlabs/puppet/lib/ruby/vendor_ruby/puppet/network/http/api/indirected_routes.rb:47:in `call'
/opt/puppetlabs/puppet/lib/ruby/vendor_ruby/puppet/network/http/route.rb:82:in `process'
org/jruby/RubyArray.java:1613:in `each'
/opt/puppetlabs/puppet/lib/ruby/vendor_ruby/puppet/network/http/route.rb:81:in `process'
/opt/puppetlabs/puppet/lib/ruby/vendor_ruby/puppet/network/http/route.rb:87:in `process'
/opt/puppetlabs/puppet/lib/ruby/vendor_ruby/puppet/network/http/route.rb:87:in `process'
/opt/puppetlabs/puppet/lib/ruby/vendor_ruby/puppet/network/http/handler.rb:60:in `process'
/opt/puppetlabs/puppet/lib/ruby/vendor_ruby/puppet/util/profiler/around_profiler.rb:58:in `profile'

Example node definition:

class { "elasticsearch":
  version => "6.3.0"
}

The module works fine on Puppet 5 but not on Puppet 4, but the documentation says it requires Puppet >= 4.5.0 < 6.0.0.

Programie commented 6 years ago

I was able to trace down the issue to the plugindir parameter of the elasticsearch class. Once I manually specify the path to the plugins dir of Elasticsearch, Puppet is running as expected.

It looks like the hiera() function, which is used in the common.yaml, is not available in Puppet 4.

tylerjl commented 6 years ago

@Programie the module is unit tested against puppet 4.5 up to version 5 and acceptance tests run for all distributions and multiple Elasticsearch versions on Puppet 4 (see the list of example tests here), so the module appears to still be working fine for the versions you indicated in testing, at least (and manually running manifests in example environments seems to work fine, as well).

It does seem that there's something wrong with the environment you're working in, though. You're probably right that the hiera call may be to blame given that it's the only class parameter that uses the hiera() function in Hiera yaml. It should be available in Puppet 4, and in any case, it would fail in CI if the function weren't available in Puppet 4.x, so I don't think that's the issue.

Is there a way to reproduce the behavior you're describing? I can't force the error when I stand up a host and apply a simple manifest to configure Elasticsearch on version 4 of Puppet.

Programie commented 6 years ago

I've tested it in a completely empty environment containing only external modules (including other ones which are not required by Elasticsearch) and the issue still exists. I will test it once again in an empty environment only containing the Elasticsearch module and it's dependencies.

Programie commented 6 years ago

OK, now I've tested it using a completely empty environment containing only the required modules, but the issue still exists.

environment.conf

modulepath = external_modules

Puppetfile

moduledir 'external_modules'

mod 'puppetlabs/apt', '4.5.1'
mod 'puppetlabs/stdlib', '4.25.1'
mod 'richardc/datacat', '0.6.2'
mod 'elastic/elastic_stack', '6.1.0'
mod 'elastic/elasticsearch', '6.3.0'

manifests/test.pp

node "mynode" {
  class { "elasticsearch":
    version => "6.3.0"
  }
}
tylerjl commented 6 years ago

So I'm using the following Vagrantfile to provision an example setup using Puppet 4, version 6.3.0 of the module, and Elasticsearch 6.3:

$ git clone https://gist.github.com/tylerjl/5cc29637040414de547801f08c8daa6b puppet
$ cd puppet
$ make

And elasticsearch seems to install/run fine. Is there something different I should be doing to get the behavior you're describing? I'm hoping there's some way to reproduce this so that we can know definitely when it's fixed with tests.

Programie commented 6 years ago

Applying the catalog locally using puppet apply also works for me, but in combination with a Puppet master, the Puppet run fails.

tylerjl commented 6 years ago

Alright: I've updated that example Vagrant setup to be master/agent, and in doing so did see some weird problems where the elasticsearch_users provider couldn't autoload, though the error message looks different what you were reporting.

At this point I think there's a bug with type/provider loading that I may need to fix with some $LOAD_PATH changes, but unsure whether it's the bug you're running into. Does the updated Vagrant setup work correctly for you, or can you get it to reproduce the erroring-out hiera() behavior?

Programie commented 6 years ago

I just tried to test it in the Vagrant VM provided by you, but the used box boxcutter/centos73 is not available.

tylerjl commented 6 years ago

Hmm, that's strange. I've updated the Vagrant setup to use a Debian Jessie box (so it's the same as the system you reported this on, as well). Does that different box work for you with make?

Programie commented 6 years ago

Sorry for the delayed answer.

I just tried your updated box but had to add apt install -y curl to the Vagrantfile as the box doesn't contain curl which is called in the Makefile. After the modification, the box worked as expected and the curl call to localhost:9200 showed the expected Elasticsearch output: That JSON with the "You Know, for Search" tagline.

Maybe this is just an issue with my Puppet setup even if it's rather strange as it only happens in version 6.x.x of the module.

Someone else also had the same issue a while ago in which you were involved, too: https://discuss.elastic.co/t/elasticsearch-puppet-module-issue/111567

tylerjl commented 6 years ago

@Programie just to be totally clear, removing the hiera() call in the data/common.yaml file fixes your issue, is that correct? If that's the case, I can try and narrow down a test to try and reproduce that by trying some more hiera tests. If that doesn't work, then removing it and just populating the string manually isn't a huge deal, but I just want to verify that's the root cause with whatever environment you're running in.

Programie commented 6 years ago

Yes, removing the hiera() call in the data/common.yaml file fixes this issue. And simply specifying the plugindir in the elasticsearch class also fixes it.

mrbanzai commented 6 years ago

For what it's worth, I encountered the same issue yesterday, running Puppet 4.8.1 (both server and agent) on CentOS 7, also resolved by setting configdir.

madelaney commented 6 years ago

@mrbanzai Can you expand on your fix?

mrbanzai commented 6 years ago

Sorry! My previous comment was a typo; it required setting plugindir as mentioned by @Programie .

mcorreafdez commented 5 years ago

Same environment, same error: master: 4.8.1 (Centos7) agent: 4.10.4 (Redhat 6.6)

@tylerjl Is able to have it fixed in future versions ?

tylerjl commented 5 years ago

I have a potential branch to fix this over in #1023. Can someone take the branch for a test drive to confirm whether this looks fixed for them in their environment?

tylerjl commented 5 years ago

The aforementioned fix PR should be included in 6.4.0