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 accept_license property to chef-ingredient. #101

Merged
merged 2 commits into from
Apr 21, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ By default, `chef_ingredient` will install using the `packages.chef.io` stable r
- `channel`: Channel to install the products from. It can be `:stable` (default), `:current` or `:unstable`.
- `package_source`: Full path to a location where the package is located. If present, this file is used for installing the package. Default `nil`.
- `timeout`: The amount of time (in seconds) to wait to fetch the installer before timing out. Default: default timeout of the Chef package resource - `900` seconds.
- `accept_license`: A boolean value that specifies if license should be accepted if it is asked for during `reconfigure`action. This option is applicable to only these products: manage, analytics, reporting and compliance. Default: `false`.

### omnibus_service

Expand Down
21 changes: 21 additions & 0 deletions libraries/chef_ingredient_provider.rb
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,27 @@ def initialize(name, run_context = nil)
not_if { get_config(new_resource.product_name).empty? }
end

# If accept_license is set, drop .license.accepted file so that
# reconfigure does not prompt for license acceptance. This is
# the backwards compatible way of accepting a Chef license.
if new_resource.accept_license && %w(analytics manage reporting compliance).include?(new_resource.product_name)
# The way we construct the data directory for a product, that looks
# like /var/opt/<product_name> is to get the config file path that
# looks like /etc/<product_name>/<product_name>.rb and do path
# manipulation.
product_data_dir_name = ::File.basename(::File.dirname(ingredient_config_file(new_resource.product_name)))
product_data_dir = ::File.join('/var/opt', product_data_dir_name)

directory product_data_dir do
recursive true
action :create
end

file ::File.join(product_data_dir, '.license.accepted') do
action :touch
end
end

execute "#{ingredient_package_name}-reconfigure" do
command "#{ingredient_ctl_command} reconfigure"
end
Expand Down
3 changes: 3 additions & 0 deletions libraries/chef_ingredient_resource.rb
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,9 @@ class ChefIngredient < Chef::Resource::LWRPBase
# Attributes for package resources used on rhel and debian platforms
attribute :options, kind_of: String
attribute :timeout, kind_of: [Integer, String, NilClass], default: nil

# Attribute to accept the license when applicable
attribute :accept_license, kind_of: [TrueClass, FalseClass], default: false
end
end
end
2 changes: 1 addition & 1 deletion libraries/helpers.rb
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ def ingredient_ctl_command
#
# Returns the ctl-command for a chef_ingredient resource
#
def ingredient_config_file
def ingredient_config_file(product_name)
ensure_mixlib_install_gem_installed!

PRODUCT_MATRIX.lookup(product_name).config_file
Expand Down
2 changes: 1 addition & 1 deletion resources/ingredient_config.rb
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
property :config, String, default: nil

action :render do
target_config = ingredient_config_file
target_config = ingredient_config_file(product_name)
return if target_config.nil?

directory ::File.dirname(target_config) do
Expand Down
8 changes: 8 additions & 0 deletions spec/unit/recipes/test_config_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,14 @@
expect(chef_run).to reconfigure_chef_server_ingredient('manage')
end

it 'creates the directory for the license acceptance file' do
expect(chef_run).to create_directory('/var/opt/chef-manage').with(recursive: true)
end

it 'creates the license acceptance file' do
expect(chef_run).to touch_file('/var/opt/chef-manage/.license.accepted')
end

it 'does not render config file using ingredient_config' do
expect(chef_run).to_not render_ingredient_config('manage')
end
Expand Down
1 change: 1 addition & 0 deletions test/fixtures/cookbooks/test/recipes/config.rb
Original file line number Diff line number Diff line change
Expand Up @@ -12,5 +12,6 @@

# Management Console - using the compat shim resource
chef_server_ingredient 'manage' do
accept_license true
action :reconfigure
end