chef-server icon indicating copy to clipboard operation
chef-server copied to clipboard

Add support for add-on configuration

Open elyscape opened this issue 9 years ago • 3 comments

Currently, there is no way to provide configuration information for the add-ons. For example, if you want to change the email address from which the management console sends emails, you have to write a custom recipe that either creates the chef_ingredient resource with the right content in config or creates an ingredient_config resource with the same. This complicates the provisioning process. Ideally, the configuration for each add-on could be specified in the attributes, much like how the list of add-ons to install can be specified.

elyscape avatar Feb 04 '16 04:02 elyscape

I apparently just hit this now that chef-manage is enforcing the 'accept license' thing. This just made spinning up chef-server more complicated than it needs to be.

mengesb avatar Apr 28 '16 19:04 mengesb

JSON encoded string, passed as node['chef-server']['addons']['config'][addon]

so, you could do something like:

node['chef-server']['addons']['config']['chef-manage'] = '"api_fqdn \"#{node[\"fqdn\"]}\"\nip_version \"ipv6\"\nnotification_email \"#{node[\"chef_admin\"]}\"\nnginx[\"ssl_protocols\"] = \"TLSv1 TLSv1.1 TLSv1.2\"\n"'

Then in recipes/addons.rb something like:

node['chef-server']['addons'].each do |addon, ver|
  chef_ingredient addon do
    config JSON.parse(node['chef-server']['addons']['config'][addon]).to_s unless node['chef-server']['addons']['config'][addon].nil?
    accept_license node['chef-server']['accept_license'] unless node['chef-server']['accept_license'].nil?
    notifies :reconfigure, "chef_ingredient[#{addon}]"
    version ver unless ver.nil?
  end
end

That was my first thought... thoughts? I'd be happy to write the patch/pull request for this, but would like some feedback as to the correct approach. Thanks!

qubitrenegade avatar Jan 03 '18 22:01 qubitrenegade

gah, drat... well, this doesn't seem to work, so maybe need to figure out another way to "encode" the config...

$ cat test_config
api_fqdn "#{node["fqdn"]}"
ip_version "ipv6"
notification_email "#{node["chef_admin"]}"
nginx["ssl_protocols"] = "TLSv1 TLSv1.1 TLSv1.2"
$ ruby -rjson -e 'puts File.read(ARGV.shift).to_json' test_config
"api_fqdn \"#{node[\"fqdn\"]}\"\nip_version \"ipv6\"\nnotification_email \"#{node[\"chef_admin\"]}\"\nnginx[\"ssl_protocols\"] = \"TLSv1 TLSv1.1 TLSv1.2\"\n"

but:

$ ruby -rjson -e 'puts JSON.parse(File.read(ARGV.shift).to_json).to_s' test_config
/opt/chefdk/embedded/lib/ruby/gems/2.3.0/gems/json-1.8.6/lib/json/common.rb:155:in `parse': 784: unexpected token at '"api_fqdn \"#{node[\"fqdn\"]}\"\nip_version \"ipv6\"\nnotification_email \"#{node[\"chef_admin\"]}\"\nnginx[\"ssl_protocols\"] = \"TLSv1 TLSv1.1 TLSv1.2\"\n"' (JSON::ParserError)
    from /opt/chefdk/embedded/lib/ruby/gems/2.3.0/gems/json-1.8.6/lib/json/common.rb:155:in `parse'
    from -e:1:in `<main>'

But the idea still stands, encode the config, pass it as an attribute, decode in the resource. I guess you can do HEREDOCs in attributes, so maybe the JSON encoding is only required if you're editing your environments/nodes directly? e.g. in your attributes/default.rb in a wrapper cookbook do:

node['chef-server']['addons']['config']['chef-manage'] = <<~EOCFG
api_fqdn "#{node["fqdn"]}"
ip_version "ipv6"
notification_email "#{node["chef_admin"]}"
nginx["ssl_protocols"] = "TLSv1 TLSv1.1 TLSv1.2"
EOCFG

qubitrenegade avatar Jan 03 '18 22:01 qubitrenegade