sous-chefs / consul

Development repository for the consul cookbook

Home Page:https://supermarket.chef.io/cookbooks/consul

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Error in configure_diplomat with Diplomat 2.5.0

evandam opened this issue Β· comments

πŸ‘» Brief Description

After the release of Diplomat 2.5.0, I'm seeing errors coming from configure_diplomat.

πŸ₯ž Cookbook version

4.3.1

πŸ‘©β€πŸ³ Chef-Infra Version

15.15.1

🎩 Platform details

Ubuntu 18.04

Steps To Reproduce

Run the following recipe with diplomat_version not set (or set to 2.5.0), and again pointing to the previous version:

# latest version (broken)
default['consul']['diplomat_version'] = '2.5.0'

# previous version (working)
default['consul']['diplomat_version'] = '2.4.4'
include_recipe 'consul::client_gem'

consul_policy 'anonymous' do
  description 'Anonymous policy'
  auth_token 'master'
  rules <-HCL.gsub(/^\s{4}/, '')
    node_prefix "" {
      policy = "read"
    }
    service_prefix "" {
      policy = "read"
    }
    operator = "read"
  HCL
  action :create
end

Logs:

Recipe: wo-consul::acl_anonymous
         * consul_policy[anonymous] action create[2021-02-10T21:57:13+00:00] INFO: Processing consul_policy[anonymous] action create (wo-consul::acl_anonymous line 19)

           ================================================================================
           Error executing action `create` on resource 'consul_policy[anonymous]'
           ================================================================================

           RuntimeError
           ------------
           The diplomat gem is required; include recipe[consul::client_gem] to install.

           Cookbook Trace:
           ---------------
           /var/tmp/kitchen/cache/cookbooks/consul/libraries/consul_policy.rb:91:in `rescue in configure_diplomat'
           /var/tmp/kitchen/cache/cookbooks/consul/libraries/consul_policy.rb:88:in `configure_diplomat'
           /var/tmp/kitchen/cache/cookbooks/consul/libraries/consul_policy.rb:62:in `action_create'

           Resource Declaration:
           ---------------------
           # In /var/tmp/kitchen/cache/cookbooks/wo-consul/recipes/acl_anonymous.rb

            19:   consul_policy 'anonymous' do
            20:     description 'Anynomous policy'
            21:     auth_token 'master'
            22:     rules <<-HCL.gsub(/^\s{4}/, '')
            23:       node_prefix "" {
            24:         policy = "read"
            25:       }
            26:       service_prefix "" {
            27:         policy = "read"
            28:       }
            29:       operator = "read"
            30:     HCL
            31:     action :create

           Compiled Resource:
           ------------------
           # Declared in /var/tmp/kitchen/cache/cookbooks/wo-consul/recipes/acl_anonymous.rb:19:in `from_file'

           consul_policy("anonymous") do
             action [:create]
             default_guard_interpreter :default
             declared_type :consul_policy
             cookbook_name "wo-consul"
             recipe_name "acl_anonymous"
             auth_token "master"
             rules "  node_prefix \"\" {\n    policy = \"read\"\n  }\n  service_prefix \"\" {\n    policy = \"read\"\n  }\n  operator = \"read\"\n"
           end

           System Info:
           ------------
           chef_version=15.15.1
           platform=ubuntu
           platform_version=18.04
           ruby=ruby 2.6.6p146 (2020-03-31 revision 67876) [x86_64-linux]
           program_name=/opt/chef/bin/chef-client
           executable=/opt/chef/bin/chef-client

I confirmed the gem is installed:

# /opt/chef/embedded/bin/gem list diplomat

*** LOCAL GEMS ***

diplomat (2.5.0)

πŸš“ Expected behavior

Same behavior as previous version and consul_policy is created.

what is the ruby version running chef ? Could it be running 2.4?

Hi @pierresouchay

Chef is using Ruby 2.6.6, still above the minimum version according to Diplomat.

# /opt/chef/embedded/bin/ruby --version
ruby 2.6.6p146 (2020-03-31 revision 67876) [x86_64-linux]

Ok, so what does the line

RuntimeError
           ------------
           The diplomat gem is required; include recipe[consul::client_gem] to install.

means exactly?

=> it means the dependency to the recipe should have been included first?

I am including the consul::client_gem recipe, and can confirm that the gem is installed. I consistently get this error trying to converge in kitchen.

it means the dependency to the recipe should have been included first?

The line can say whatever, it's included πŸ€¦β€β™‚οΈ

Ok, so, what's the issue?

Two changes have been made:

  • increasing the minimum Ruby version to 2.5 => does not seem to be the culprit
  • increasing the minimum version of faraday => might be the issue?

Any idea?

/me hate ruby dependencies

Not sure what the issue is, just reporting the behavior πŸ˜…

The gem is definitely installed and doesn't seem like any dependency issues:

       Recipe: consul::client_gem
         * chef_gem[diplomat] action install[2021-02-10T22:49:49+00:00] INFO: Processing chef_gem[diplomat] action install (consul::client_gem line 8)
       [2021-02-10T22:49:51+00:00] INFO: chef_gem[diplomat] installed diplomat at 2.5.0

           - install version 2.5.0 of package diplomat

I can also use the gem in /opt/chef/embedded/bin/pry seemingly okay πŸ€·β€β™‚οΈ:

[1] pry(main)> require 'diplomat'
=> true
[3] pry(main)> Diplomat.configure do |config|
[3] pry(main)*   config.acl_token = 'master'
[3] pry(main)* end
=> "master"
[4] pry(main)> Diplomat::Policy.list
=> [{"ID"=>"00000000-0000-0000-0000-000000000001",
  "Name"=>"global-management",
  "Description"=>"Builtin Policy that grants unlimited access",
  "Datacenters"=>nil,
  "Hash"=>"swIQt6up+s0cV4kePfJ2aRdKCLaQyykF4Hl1Nfdeumk=",
  "CreateIndex"=>16,
  "ModifyIndex"=>16}]

In the meantime pinning the gem to 2.4.4 solves my problem

@evandam Could you try to modify the cookbook, change the file libraries/consul_policy.rb and modify line 135 and 137 to:

        begin
          require 'diplomat'
        rescue LoadError => err
          raise 'The diplomat gem is required; ' \
                'include recipe[consul::client_gem] to install: #{err} / #{err.inspect}'
        end

=> then re-launch convergence (skipping the cookbook updates if necessary) to get a maybe better error message?

Still I suspect faraday to be the culprit... maybe the error message will be clearer

In your shell, could you also do:

require 'faraday'
Faraday::VERSION

Good call, it's related to Faraday

           ================================================================================
           Error executing action `create` on resource 'consul_policy[anonymous]'
           ================================================================================

           RuntimeError
           ------------
           The diplomat gem is required; include recipe[consul::client_gem] to install: Unable to activate diplomat-2.5.0, because faraday-1.0.1 conflicts with faraday (~> 1.3) / #<Gem::ConflictError: Unable to activate diplomat-2.5.0, because faraday-1.0.1 conflicts with faraday (~> 1.3)>

           Cookbook Trace:
           ---------------
           /var/tmp/kitchen/cache/cookbooks/consul/libraries/consul_policy.rb:91:in `rescue in configure_diplomat'
           /var/tmp/kitchen/cache/cookbooks/consul/libraries/consul_policy.rb:88:in `configure_diplomat'
           /var/tmp/kitchen/cache/cookbooks/consul/libraries/consul_policy.rb:62:in `action_create'

           Resource Declaration:
           ---------------------
           suppressed sensitive resource output

           Compiled Resource:
           ------------------
           suppressed sensitive resource output

           System Info:
           ------------
           chef_version=15.15.1
           platform=ubuntu
           platform_version=18.04
           ruby=ruby 2.6.6p146 (2020-03-31 revision 67876) [x86_64-linux]
           program_name=/opt/chef/bin/chef-client
           executable=/opt/chef/bin/chef-client

       [2021-02-10T23:22:29+00:00] INFO: Running queued delayed notifications before re-raising exception

       Running handlers:
       [2021-02-10T23:22:29+00:00] ERROR: Running exception handlers
       Running handlers complete
       [2021-02-10T23:22:29+00:00] ERROR: Exception handlers complete
       Chef Infra Client failed. 7 resources updated in 34 seconds
       [2021-02-10T23:22:29+00:00] FATAL: Stacktrace dumped to /var/tmp/kitchen/cache/chef-stacktrace.out
       [2021-02-10T23:22:29+00:00] FATAL: Please provide the contents of the stacktrace.out file if you file a bug report
       [2021-02-10T23:22:29+00:00] FATAL: RuntimeError: consul_policy[anonymous] (wo-consul::acl_anonymous line 19) had an error: RuntimeError: The diplomat gem is required; include recipe[consul::client_gem] to install: Unable to activate diplomat-2.5.0, because faraday-1.0.1 conflicts with faraday (~> 1.3) / #<Gem::ConflictError: Unable to activate diplomat-2.5.0, because faraday-1.0.1 conflicts with faraday (~> 1.3)>

Hello @evandam & @scalp42

I fixed the issue in diplomat... I was very suspicious about the GEM recent bump in chef-client: chef/chef@72439d4#diff-89cade48462044ee1b672dc5f4c3ec250fbd29effcd8932096a23c1283c6731fL203

And if you 10 minutes to spend, I can recommend my last article about Consul performance with Streaming: https://medium.com/criteo-engineering/consul-streaming-whats-behind-it-6f44f77a5175?source=friends_link&sk=a4cf7321bf6f9d50807c7256feee21c5 :-)

Have a good day!

Thanks @pierresouchay! Just confirmed the new version of the gem works πŸ‘Œ

Still, I recommend to vote for #583 ... would have helped quite a lot the diagnostic