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

fixing resources reporting as updated #142

Merged
merged 6 commits into from
Nov 3, 2016

Conversation

jeremymv2
Copy link
Contributor

Description

This PR removes the dependency on chef_chandler because that cookbook's LWRP reports updated resources for each handler enabled. It also removes the inspec custom resource and simply makes it a chef_gem resource with compile_time true. This makes the assumption that inspec gem version is ALWAYS specified via attribute to a specific SEMVER version (node['audit']['inspec_version']) - "latest" is no longer allowed.

Issues Resolved

This addresses #138

Check List

Signed-off-by: Jeremy J. Miller [email protected]

@jeremymv2
Copy link
Contributor Author

The result of testing collector = chef-server

Notice 0/x resources updated.

root@node:/tmp/vagrant-chef# chef-client -c client.rb
[2016-11-02T22:46:54+00:00] INFO: Forking chef instance to converge...
Starting Chef Client, version 12.15.19
[2016-11-02T22:46:54+00:00] INFO: *** Chef 12.15.19 ***
[2016-11-02T22:46:54+00:00] INFO: Platform: x86_64-linux
[2016-11-02T22:46:54+00:00] INFO: Chef-client pid: 2889
[2016-11-02T22:46:56+00:00] INFO: Run List is [recipe[audit_wrapper::default]]
[2016-11-02T22:46:56+00:00] INFO: Run List expands to [audit_wrapper::default]
[2016-11-02T22:46:56+00:00] INFO: Starting Chef Run for node
[2016-11-02T22:46:56+00:00] INFO: Running start handlers
[2016-11-02T22:46:56+00:00] INFO: Start handlers complete.
[2016-11-02T22:46:56+00:00] INFO: HTTP Request Returned 404 Not Found:
resolving cookbooks for run list: ["audit_wrapper::default"]
[2016-11-02T22:46:56+00:00] INFO: Loading cookbooks [[email protected], [email protected], [email protected]]
Synchronizing Cookbooks:
  - audit_wrapper (0.1.0)
  - audit (2.0.0)
  - compat_resource (12.16.1)
Installing Cookbook Gems:
Compiling Cookbooks...
Recipe: audit::default
  * chef_gem[inspec] action install (up to date)
[2016-11-02T22:46:56+00:00] INFO: loading handler from /var/chef/cache/cookbooks/audit/files/default/handler/audit_report
  Converging 1 resources
  * chef_gem[inspec] action install (up to date)
[2016-11-02T22:46:56+00:00] INFO: Chef Run complete in 0.283401384 seconds

Running handlers:
[2016-11-02T22:46:56+00:00] INFO: Running report handlers
[2016-11-02T22:46:56+00:00] WARN: Format is json-min
[2016-11-02T22:46:56+00:00] INFO: Initialize InSpec
[2016-11-02T22:46:56+00:00] INFO: Running tests from: [{:name=>"linux", :compliance=>"base/linux"}]
[2016-11-02T22:46:57+00:00] INFO: Reporting to chef-server
[2016-11-02T22:46:57+00:00] INFO: Control Profile: ["linux"]
[2016-11-02T22:46:57+00:00] INFO: Control Profil: linux
[2016-11-02T22:46:57+00:00] INFO: Compliance Profils: [{:owner=>"base", :profile_id=>"linux"}]
[2016-11-02T22:46:57+00:00] INFO: Report to Chef Server: https://chef-server.test/compliance/organizations/brewinc/inspec
  - Chef::Handler::AuditReport
Running handlers complete
[2016-11-02T22:46:57+00:00] INFO: Report handlers complete
Chef Client finished, 0/2 resources updated in 02 seconds
root@node:/tmp/vagrant-chef#

Copy link
Contributor

@chris-rock chris-rock left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Great improvement @jeremymv2

end

def load_audit_handler
libpath = ::File.join(cookbook_handler_path, 'audit_report')
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Very nice approach!


# install inspec
inspec 'inspec' do
chef_gem 'inspec' do
version node['audit']['inspec_version']
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Any reason why we are not using version new_resource.version if new_resource.version != 'latest'?

@@ -13,4 +13,3 @@
chef_version '>= 12.5.1' if respond_to?(:chef_version)

depends 'compat_resource'
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@lamont-granquist Is there any real reason why we need compat_resource

@jeremymv2
Copy link
Contributor Author

This now supports node['audit']['inspec_version'] = 'latest'

Signed-off-by: Jeremy J. Miller <[email protected]>
def verify_inspec_version(inspec_version)
require 'inspec'
# check that we have the right inspec version
if Inspec::VERSION != inspec_version && inspec_version !='latest'
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@jeremymv2 Do you think we should keep that warning. May be very helpful for debugging?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good idea @chris-rock
I've moved it under load_inspec_libs function which seemed appropriate :)

@@ -3,6 +3,12 @@
# load all the inspec and compliance bundle requirements
def load_inspec_libs
require 'inspec'
if Inspec::VERSION != node['audit']['inspec_version'] && node['audit']['inspec_version'] !='latest'
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That is a very nice idea

@chris-rock
Copy link
Contributor

Awesome work @jeremymv2

@chris-rock chris-rock merged commit 1ea498b into chef-boneyard:master Nov 3, 2016
@jeremymv2 jeremymv2 deleted the fixing_updated_resources branch November 3, 2016 13:56
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

3 participants