Skip to content
This repository has been archived by the owner on Jan 8, 2019. It is now read-only.

Commit

Permalink
Merge pull request #7 from mengesb/chef_mlsa
Browse files Browse the repository at this point in the history
Handle Chef MLSA
  • Loading branch information
mengesb committed May 12, 2016
2 parents 90feb44 + 2faf92c commit d7dc936
Show file tree
Hide file tree
Showing 7 changed files with 57 additions and 6 deletions.
7 changes: 7 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,13 @@ chef-compliance CHANGELOG

This file is used to list changes made in each version of the chef-compliance cookbook.

0.1.1
-----
- [Brian Menges](https://github.com/mengesb) - Increment `chef_ingredient` dependency to `>= 0.18.4`
- [Brian Menges](https://github.com/mengesb) - Updates to handle [Chef MLSA](https://www.chef.io/online-master-agreement/)
- [Brian Menges](https://github.com/mengesb) - Add handler to ensure API FQDN can be resolved
- [Brian Menges](https://github.com/mengesb) - Better handling of version

0.1.0
-----
- [Brian Menges](https://github.com/mengesb) - Initial release of chef-compliance
Expand Down
8 changes: 7 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -64,13 +64,19 @@ Attributes
<td>Arbitrary config to add to chef-compliance.rb</td>
<td><tt>{}</tt></td>
</tr>
<tr>
<td><tt>['chef-compliance']['accept_license']</tt></td>
<td>Boolean</td>
<td>Indication that you accept the Chef MLSA</td>
<td><tt>false</tt></td>
</tr>
</table>

Usage
-----
#### chef-compliance::default

Add chef-compliance to your run list.
Add chef-compliance to your run list and accept the license agreement by setting `node['chef-compliance']['accept_license'] = true`


# License and Authors
Expand Down
5 changes: 5 additions & 0 deletions attributes/default.rb
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,11 @@
default['chef-compliance']['package_source'] = nil
default['chef-compliance']['channel'] = :stable

# Chef MLSA
# https://www.chef.io/blog/2016/04/26/changes-to-how-chef-products-handle-licenses/
# https://www.chef.io/online-master-agreement/
default['chef-complaince']['accept_license'] = false

# The Chef Compliance Server must have an API FQDN set.
# https://docs.chef.io/install_compliance.html
default['chef-compliance']['api_fqdn'] = node['fqdn']
Expand Down
23 changes: 23 additions & 0 deletions libraries/helpers.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
# Reference: https://github.com/chef-cookbooks/chef-server/blob/master/libraries/helpers.rb
module ChefComplianceCookbook
module Helpers
def api_fqdn_available?
return false if node['chef-compliance'].nil?
return false if node['chef-compliance']['api_fqdn'].nil?
!node['chef-compliance']['api_fqdn'].empty?
end

def api_fqdn_resolves?
ChefIngredientCookbook::Helpers.fqdn_resolves?(
node['chef-compliance']['api_fqdn']
)
end

def repair_api_fqdn
fe = Chef::Util::FileEdit.new('/etc/hosts')
fe.insert_line_if_no_match(/#{node['chef-compliance']['api_fqdn']}/,
"127.0.0.1 #{node['chef-compliance']['api_fqdn']}")
fe.write_file
end
end
end
4 changes: 2 additions & 2 deletions metadata.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@
license 'Apache 2.0'
description 'Installs/Configures chef-compliance'
long_description IO.read(File.join(File.dirname(__FILE__), 'README.md'))
version '0.1.0'
version '0.1.1'

depends 'chef-ingredient', '>= 0.12.0'
depends 'chef-ingredient', '>= 0.18.4'

source_url 'https://github.com/mengesb/chef-compliance' if respond_to?(:source_url)
issues_url 'https://github.com/mengesb/chef-compliance/issues' if respond_to?(:issues_url)
14 changes: 13 additions & 1 deletion recipes/default.rb
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,18 @@
# limitations under the License.
#

ruby_block 'ensure node can resolve API FQDN' do
extend ChefComplianceCookbook::Helpers
block { repair_api_fqdn }
only_if { api_fqdn_available? }
not_if { api_fqdn_resolves? }
end

chef_ingredient 'compliance' do
channel node['chef-compliance']['channel'].to_sym
version node['chef-compliance']['version']
version node['chef-compliance']['version'] unless node['chef-compliance']['version'].nil?
package_source node['chef-compliance']['package_source']
accept_license node['chef-compliance']['accept_license']
action :upgrade
end

Expand All @@ -37,3 +45,7 @@
action :create
notifies :reconfigure, 'chef_ingredient[compliance]', :immediately
end

ingredient_config 'compliance' do
notifies :reconfigure, 'chef_ingredient[compliance]', :immediately
end
2 changes: 0 additions & 2 deletions templates/default/chef-compliance.rb.erb
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,9 @@

topology "standalone"

<% unless node['chef-compliance']['api_fqdn'].nil? || node['chef-compliance']['api_fqdn'].empty? -%>
<% if node['chef-compliance']['configuration']['compliance_fqdn'].nil? -%>
compliance_fqdn "<%= node['chef-compliance']['api_fqdn'] %>"
<% end -%>
<% end -%>

<% node['chef-compliance']['configuration'].each_pair do |component, tunables| -%>
<% case tunables -%>
Expand Down

0 comments on commit d7dc936

Please sign in to comment.