Skip to content

Commit 681bb0e

Browse files
authored
v2.2.0 (#7)
* WIP * Do it CircleCI! * WIP [skip ci] * Moved circleci config to root. Not currently doing any other script includes etc. [skip ci] * awslogsd their python setup sucks! [skip ci] * awslogsd their python setup sucks! [skip ci] * 2.2.0 - Read Changelog * 2.2.0 - Read Changelog * 2.2.0 - Read Changelog
1 parent d8ba2ec commit 681bb0e

File tree

22 files changed

+625
-275
lines changed

22 files changed

+625
-275
lines changed

.kitchen.yml

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ verifier:
44
name: inspec
55
format: <%= ENV['CI'] ? 'junit' : 'cli' %>
66
<% if ENV['CI'] %>
7-
output: "test-reports/%{platform}_%{suite}_inspec.xml"
7+
output: "reports/%{platform}_%{suite}_inspec.xml"
88
<% end %>
99

1010
platforms:
@@ -156,8 +156,10 @@ suites:
156156
git: https://github.com/bonusbits/inspec_bootstrap.git
157157
- name: bonusbits_base
158158
git: https://github.com/bonusbits/inspec_bonusbits_base.git
159+
# - path: ../inspec_bonusbits_base
159160
attributes:
160161
chef_version: '12.19.36'
162+
configure_backups: 'true'
161163
includes: ["amazon-ec2"]
162164

163165
- name: ec2_base_epel_repo
@@ -241,7 +243,6 @@ suites:
241243
inspec_tests:
242244
- name: bootstrap
243245
git: https://github.com/bonusbits/inspec_bootstrap.git
244-
# - path: test/inspec_bonusbits_base
245246
- name: bonusbits_base
246247
git: https://github.com/bonusbits/inspec_bonusbits_base.git
247248
attributes:
@@ -261,6 +262,7 @@ suites:
261262
git: https://github.com/bonusbits/inspec_bootstrap.git
262263
- name: bonusbits_base
263264
git: https://github.com/bonusbits/inspec_bonusbits_base.git
265+
# - path: ../inspec_bonusbits_base
264266
attributes:
265267
chef_version: '12.19.36'
266268
attributes:

CHANGELOG.md

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,14 @@
11
## CHANGE LOG
22

3+
## 2.2.0 - 06/14/2017 - Levon Becker
4+
* Updated Cloudwatch Logs logic for CentOS and RHEL support.
5+
* Switched to using bonusbits_library shell library to DRY up some code
6+
* Added Cookbook version badge to README
7+
* Added backup to s3 logic
8+
* Added Cloudwatch monitoring agent setup
9+
* Added default aws region for testing some logic outside AWS
10+
* Fixed awslogs additional logs logic for if nil
11+
312
## 2.1.9 - 04/15/2017 - Levon Becker
413
* Removed unnecessary attributes in kitchen config now that auto deployment discovery wrote.
514
* Fixed CircleCI detection

Gemfile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
source 'https://rubygems.org'
22

33
gem 'berkshelf', '~> 5.6'
4-
gem 'rake', '~> 12.0.0'
4+
gem 'rake', '~> 12.0'
55

66
group :style do
77
gem 'chef', '12.19.36'

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
# Bonus Bits Base Cookbook
22
[![Circle CI](https://circleci.com/gh/bonusbits/bonusbits_base/tree/master.svg?style=shield)](https://circleci.com/gh/bonusbits/bonusbits_base/tree/master)
3+
[![Chef cookbook](https://img.shields.io/badge/cookbook-v2.2.0-blue.svg)](https://github.com/bonusbits/bonusbits_base)
34
[![Join the chat at https://gitter.im/bonusbits/bonusbits_base](https://badges.gitter.im/bonusbits/bonusbits_base.svg)](https://gitter.im/bonusbits/bonusbits_base?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge&utm_content=badge)
45

56
# Purpose

Rakefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ namespace :unit do
2828
RSpec::Core::RakeTask.new(:circleci_rspec) do |test|
2929
# t.fail_on_error = false
3030
test.rspec_opts =
31-
'--no-drb -r rspec_junit_formatter --format RspecJunitFormatter -o $CIRCLE_TEST_REPORTS/rspec/junit.xml'
31+
'--no-drb -r rspec_junit_formatter --format RspecJunitFormatter -o reports/rspec.xml'
3232
end
3333
end
3434

attributes/aws.rb

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,17 @@
11
default['bonusbits_base']['aws']['install_tools'] = false
2+
23
default['bonusbits_base']['aws']['inside'] =
34
if node['bonusbits_base']['deployment_location'] == 'aws'
45
true
56
else
67
false
78
end
9+
810
default['bonusbits_base']['aws']['region'] =
911
if node['bonusbits_base']['aws']['inside']
1012
node['ec2']['placement_availability_zone'].slice(0..-2)
1113
else
12-
'unknown'
14+
'us-west-2'
1315
end
1416

1517
# Debug

attributes/backups.rb

Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
default['bonusbits_base']['backups'].tap do |backups|
2+
backups['configure'] = false
3+
4+
# Paths
5+
backups['local_tmp_path'] = '/tmp/backups'
6+
# Array of Paths to backup
7+
backups['backup_paths'] = %w(/etc /opt)
8+
backups['script_filename'] = 'backup_to_s3.rb'
9+
backups['script_fullname'] = "/usr/bin/#{node['bonusbits_base']['backups']['script_filename']}"
10+
script_fullname = node['bonusbits_base']['backups']['script_fullname']
11+
backups['cron_command'] =
12+
if ::File.exist?('/opt/chef/embedded/bin/ruby')
13+
"/opt/chef/embedded/bin/ruby #{script_fullname}"
14+
elsif ::File.exist?('/opt/chefdk/embedded/bin/ruby')
15+
"/opt/chefdk/embedded/bin/ruby #{script_fullname}"
16+
elsif ::File.exist?('/usr/bin/ruby')
17+
"/usr/bin/ruby #{script_fullname}"
18+
else
19+
raise 'ERROR: Ruby Path Not Found!'
20+
end
21+
22+
# Filename
23+
backups['filename'] =
24+
if node['bonusbits_base']['aws']['inside']
25+
"#{node['ec2']['instance_id']}-backup.tar.gz"
26+
else
27+
'backups.tar.gz'
28+
end
29+
30+
# S3
31+
## Recommended to turn on Versioning and add Lifecycle to bucket
32+
backups['s3_bucket_name'] = 'backup_bucket' # !! Required Override !!
33+
filename = node['bonusbits_base']['backups']['filename']
34+
env = run_state['detected_environment']
35+
s3_backup_bucket = node['bonusbits_base']['backups']['s3_bucket_name']
36+
backups['s3_full_path'] = "#{s3_backup_bucket}/backups/#{env}/#{filename}"
37+
38+
# Cron
39+
## Default is Daily at 11PM Server Time
40+
backups['minutes'] = '0'
41+
backups['hours'] = '23'
42+
backups['days'] = '*'
43+
backups['month'] = '*'
44+
backups['weekday'] = '*'
45+
46+
# Backup Logs
47+
backups['configure_log_rotate'] = true
48+
backups['log_path'] = '/var/log/backups.log'
49+
end
50+
51+
# Debug
52+
message_list = [
53+
'',
54+
'** Backups **',
55+
"Configure (#{node['bonusbits_base']['backups']['configure']})",
56+
"Backup Filename (#{node['bonusbits_base']['backups']['filename']})",
57+
"Script Filename (#{node['bonusbits_base']['backups']['script_filename']})",
58+
"Script Fullname (#{node['bonusbits_base']['backups']['script_fullname']})",
59+
"Local Temp Path (#{node['bonusbits_base']['backups']['local_tmp_path']})",
60+
"S3 Full Path (#{node['bonusbits_base']['backups']['s3_full_path']})",
61+
"Config Log Rotate (#{node['bonusbits_base']['backups']['configure_log_rotate']})",
62+
"Log Path (#{node['bonusbits_base']['backups']['log_path']})"
63+
]
64+
message_list.each do |message|
65+
Chef::Log.warn(message)
66+
end

attributes/cloudwatch.rb

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
default['bonusbits_base']['cloudwatch'].tap do |cloudwatch|
2+
cloudwatch['configure'] = true
3+
4+
# Monitoring Scripts (AWS Examples Default)
5+
cloudwatch['zip_filename'] = 'CloudWatchMonitoringScripts-1.2.1.zip'
6+
zip_filename = node['bonusbits_base']['cloudwatch']['zip_filename']
7+
cloudwatch['scripts_url'] =
8+
"http://aws-cloudwatch.s3.amazonaws.com/downloads/#{zip_filename}"
9+
cloudwatch['zip_fullname'] = "#{node['bonusbits_base']['local_file_cache']}/#{zip_filename}"
10+
11+
# Cron
12+
cloudwatch['cron_command'] = '/opt/aws-scripts-mon/mon-put-instance-data.pl'
13+
cloudwatch['cron_command'] += ' --mem-util --mem-used'
14+
cloudwatch['cron_command'] += ' --mem-avail --disk-space-util'
15+
cloudwatch['cron_command'] += ' --disk-path=/ --from-cron'
16+
end
17+
18+
# Debug
19+
message_list = [
20+
'',
21+
'** CloudWatch Monitoring **',
22+
"Configure (#{node['bonusbits_base']['cloudwatch']['configure']})",
23+
"Zip Filename (#{node['bonusbits_base']['cloudwatch']['zip_filename']})",
24+
"Zip Fullname (#{node['bonusbits_base']['cloudwatch']['zip_fullname']})",
25+
"Scripts URL (#{node['bonusbits_base']['cloudwatch']['scripts_url']})",
26+
"Cron Command (#{node['bonusbits_base']['cloudwatch']['cron_command']})"
27+
]
28+
message_list.each do |message|
29+
Chef::Log.warn(message)
30+
end

attributes/cloudwatch_logs.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
default['bonusbits_base']['cloudwatch_logs']['configure'] = true
22
default['bonusbits_base']['cloudwatch_logs']['logs_group_name'] = 'kitchen-bonusbits-base'
3-
# default['bonusbits_base']['cloudwatch_logs']['additional_logs'] = nil
3+
default['bonusbits_base']['cloudwatch_logs']['additional_logs'] = nil
44
# additional_logs = node['bonusbits_base']['cloudwatch_logs']['additional_logs'].nil? ? false : true
55

66
# Debug

attributes/default.rb

Lines changed: 65 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -7,59 +7,72 @@
77
'dev'
88
end
99

10-
# Determine Deployment Type
11-
default['bonusbits_base']['deployment_type'] =
12-
if node['virtualization']['system'] == 'docker'
13-
# if node['virtualization']['systems']['docker'] == 'guest'
14-
'docker'
15-
elsif node['virtualization']['system'] == 'lxc'
16-
'lxc'
17-
elsif node['virtualization']['system'] == 'lxd'
18-
'lxd'
19-
elsif node['virtualization']['system'] == 'kvm'
20-
'kvm'
21-
elsif node['virtualization']['system'] == 'vbox'
22-
'vbox'
23-
elsif BonusBits::Discovery.ec2?(node['fqdn'], node['platform_family'])
24-
'ec2'
25-
else
26-
'other'
27-
end
10+
default['bonusbits_base'].tap do |root|
11+
# Determine Deployment Type
12+
root['deployment_type'] =
13+
if node['virtualization']['system'] == 'docker'
14+
# if node['virtualization']['systems']['docker'] == 'guest'
15+
'docker'
16+
elsif node['virtualization']['system'] == 'lxc'
17+
'lxc'
18+
elsif node['virtualization']['system'] == 'lxd'
19+
'lxd'
20+
elsif node['virtualization']['system'] == 'kvm'
21+
'kvm'
22+
elsif node['virtualization']['system'] == 'vbox'
23+
'vbox'
24+
elsif BonusBits::Discovery.ec2?(node['fqdn'], node['platform_family'])
25+
'ec2'
26+
else
27+
'other'
28+
end
2829

29-
# Determine Deployment Location
30-
## Circleci Logic Does not work if spawning Docker
31-
## containers in CircleCi because nested VM. Override in Kitchen Config
32-
default['bonusbits_base']['deployment_location'] =
33-
if ENV['CIRCLECI']
34-
'circleci'
35-
elsif BonusBits::Discovery.aws?(node['fqdn'], node['platform_family'])
36-
'aws'
37-
else
38-
'local'
39-
end
30+
# Determine Deployment Location
31+
## Circleci Logic Does not work if spawning Docker
32+
## containers in CircleCi because nested VM. Override in Kitchen Config
33+
root['deployment_location'] =
34+
if ENV['CIRCLECI']
35+
'circleci'
36+
elsif BonusBits::Discovery.aws?(node['fqdn'], node['platform_family'])
37+
'aws'
38+
else
39+
'local'
40+
end
4041

41-
# Determine Deployment Method
42-
## Mostly for Conditioning Audit Cookbook (Kitchen Handles the Audit when Used)
43-
## TODO: Added vbox discovery?
44-
deployment_location = node['bonusbits_base']['deployment_location']
45-
deployment_type = node['bonusbits_base']['deployment_type']
46-
deployment_location_local = deployment_location == 'local'
47-
deployment_type_docker = deployment_type == 'docker'
42+
# Determine Deployment Method
43+
## Mostly for Conditioning Audit Cookbook (Kitchen Handles the Audit when Used)
44+
## TODO: Added vbox discovery?
45+
deployment_location = node['bonusbits_base']['deployment_location']
46+
deployment_type = node['bonusbits_base']['deployment_type']
47+
deployment_location_local = deployment_location == 'local'
48+
deployment_type_docker = deployment_type == 'docker'
4849

49-
default['bonusbits_base']['deployment_method'] =
50-
if ::File.directory?('/tmp/kitchen')
51-
'kitchen'
52-
elsif ::File.exist?('/var/lib/cloud/instance/scripts/part-001')
53-
'cloudformation'
54-
elsif deployment_type_docker && deployment_location_local
55-
'dockerfile'
56-
elsif deployment_type_docker
57-
'dockerimage'
58-
else
59-
'unknown'
60-
end
50+
root['deployment_method'] =
51+
if ::File.directory?('/tmp/kitchen')
52+
'kitchen'
53+
elsif ::File.exist?('/var/lib/cloud/instance/scripts/part-001')
54+
'cloudformation'
55+
elsif deployment_type_docker && deployment_location_local
56+
'dockerfile'
57+
elsif deployment_type_docker
58+
'dockerimage'
59+
else
60+
'unknown'
61+
end
6162

62-
default['bonusbits_base']['local_file_cache'] = Chef::Config[:file_cache_path]
63+
# File Cache
64+
root['local_file_cache'] = Chef::Config[:file_cache_path]
65+
66+
# Chef Install Path
67+
root['chef_path'] =
68+
if ::File.directory?('/opt/chef')
69+
'/opt/chef'
70+
elsif ::File.directory?('/opt/chefdk')
71+
'/opt/chefdk'
72+
else
73+
raise 'ERROR: Chef Install Path Not Found!'
74+
end
75+
end
6376

6477
# Debug
6578
message_list = [
@@ -68,7 +81,9 @@
6881
"Detected Environment (#{run_state['detected_environment']})",
6982
"Deployment Type (#{node['bonusbits_base']['deployment_type']})",
7083
"Deployment Location (#{node['bonusbits_base']['deployment_location']})",
71-
"Deployment Method (#{node['bonusbits_base']['deployment_method']})"
84+
"Deployment Method (#{node['bonusbits_base']['deployment_method']})",
85+
"Local File Cache (#{node['bonusbits_base']['local_file_cache']})",
86+
"Chef Install Path (#{node['bonusbits_base']['chef_path']})"
7287
]
7388
message_list.each do |message|
7489
Chef::Log.warn(message)

0 commit comments

Comments
 (0)