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

Add support for add-on configuration #112

Open
elyscape opened this issue Feb 4, 2016 · 3 comments
Open

Add support for add-on configuration #112

elyscape opened this issue Feb 4, 2016 · 3 comments
Labels
Type: Enhancement Adds new functionality.

Comments

@elyscape
Copy link

elyscape commented Feb 4, 2016

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.

@mengesb
Copy link
Contributor

mengesb commented Apr 28, 2016

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.

@qubitrenegade
Copy link

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
Copy link

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

@tas50 tas50 added Type: Enhancement Adds new functionality. and removed Type: Feature Request labels Jan 4, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Type: Enhancement Adds new functionality.
Projects
None yet
Development

No branches or pull requests

4 participants