diff --git a/.kitchen.yml b/.kitchen.yml index df1d0b12..3700f0a3 100644 --- a/.kitchen.yml +++ b/.kitchen.yml @@ -37,13 +37,10 @@ suites: acl_default_policy: deny excludes: - windows-2012r2 + - name: client named_run_list: client - attributes: - consul: - config: - server: false - bootstrap_expect: 1 + - name: git attributes: go: diff --git a/libraries/consul_config.rb b/libraries/consul_config.rb index d9480183..ca050537 100644 --- a/libraries/consul_config.rb +++ b/libraries/consul_config.rb @@ -90,7 +90,7 @@ class ConsulConfig < Chef::Resource attribute(:rejoin_after_leave, equal_to: [true, false], default: true) attribute(:serf_lan_bind, kind_of: String) attribute(:serf_wan_bind, kind_of: String) - attribute(:server, equal_to: [true, false], default: true) + attribute(:server, equal_to: [true, false]) attribute(:server_name, kind_of: String) attribute(:session_ttl_min, kind_of: String) attribute(:skip_leave_on_interrupt, equal_to: [true, false], default: false) @@ -192,8 +192,9 @@ def to_json for_keeps << %i(ca_file cert_file key_file) if tls? for_keeps = for_keeps.flatten - config = to_hash.keep_if do |k, _| - for_keeps.include?(k.to_sym) + # Filter out undefined attributes and keep only those listed above + config = to_hash.keep_if do |k, v| + !v.nil? && for_keeps.include?(k.to_sym) end.merge(options) JSON.pretty_generate(Hash[config.sort_by { |k, _| k.to_s }], quirks_mode: true) end diff --git a/test/spec/libraries/consul_config_spec.rb b/test/spec/libraries/consul_config_spec.rb index 2a1acc68..389c0058 100644 --- a/test/spec/libraries/consul_config_spec.rb +++ b/test/spec/libraries/consul_config_spec.rb @@ -39,7 +39,6 @@ .with(content: <<-EOH.chomp.gsub(/^ /, '')) { "recursor": "foo", - "server": true, "translate_wan_addrs": true, "verify_incoming": false, "verify_outgoing": false