Skip to content

Instantly share code, notes, and snippets.

************cat myfile |grep -v ^#|grep -v '#.*'|wc -l
5
************cat myfile |wc -l
85
saschas-MacBook-Air:cookbooks sascha$ cat Gemfile.lock
GEM
remote: https://rubygems.org/
specs:
builder (3.2.0)
chef (11.4.0)
erubis
highline (>= 1.6.9)
json (>= 1.4.4, <= 1.7.7)
mixlib-authentication (>= 1.3.0)
@sbates
sbates / testing on the bleeding edge works
Last active December 15, 2015 13:39
bleeding edges can work - there's an error at the end but it's from the chef converge as I haven't actually configured anything yet.
saschas-MacBook-Air:chef-ci sascha$ cat Gemfile
source 'https://rubygems.org'
gem 'berkshelf', '1.4.0.rc1'
gem 'test-kitchen', '1.0.0.alpha.2', :group => :integration
gem 'kitchen-vagrant', '0.7.4', :group => :integration
gem 'vagrant', '1.1.5.dev'
saschas-MacBook-Air:chef-ci sascha$ time kitchen test
-----> Starting Kitchen
def chef_block(arr) def chef_block(arr)
arr << %{ c.vm.provision :chef_solo do |chef|} arr << %{ c.vm.provision :chef_solo do |chef|}
arr << %{ chef.log_level = #{vagrant_logger_level} arr << %{ chef.log_level = #{vagrant_logger_level}
> arr << %{ chef.cookbooks_path = "/Users/sascha/cli
arr << %{ chef.run_list = #{instance.run_list.insp arr << %{ chef.run_list = #{instance.run_list.insp
arr << %{ chef.json = #{instance.attributes.to_s}} arr << %{ chef.json = #{instance.attributes.to_s}}
if instance.suite.data_bags_path if instance.suite.data_bags_path
arr << %{ chef.data_bags_path = "#{instance.suit arr << %{ chef.data_bags_path = "#{instance.suit
end end
[centos-6.3] Waiting for VM to boot. This can take a few minutes.
/Users/a766618/.rvm/gems/ruby-1.9.3-p327/gems/vagrant-1.0.5/lib/vagrant/action/vm/boot.rb:41:in `block in wait_for_boot': The VM failed to remain in the "running" state while attempting to boot. (Vagrant::Errors::VMFailedToRun)
This is normally caused by a misconfiguration or host system incompatibilities.
Please open the VirtualBox GUI and attempt to boot the virtual machine
manually to get a more informative error message.
from /Users/a766618/.rvm/gems/ruby-1.9.3-p327/gems/vagrant-1.0.5/lib/vagrant/action/vm/boot.rb:28:in `times'
from /Users/a766618/.rvm/gems/ruby-1.9.3-p327/gems/vagrant-1.0.5/lib/vagrant/action/vm/boot.rb:28:in `wait_for_boot'
# wrapper overrides
# override attributes are being set here in order to use the base solr cookbook without direct modification
override[:solr][:home] = "/opt/solr/solr-home"
override[:solr][:configxml][:destdir] = "/opt/solr/solr-home/products/conf"
override[:solr][:configxml][:cookbook_loc] = "projectX"
@sbates
sbates / cksum.rb
Last active December 10, 2015 08:19
using the artifactory plugin for generating sha256 checksums, I then wrote some provider code to figure it out on the fly. This keeps chef from having to download all the artifacts first and calculate their checksums; this really speeds up chef runs on slow network days and cuts down on the number of things downloading from our Artifactory server.
# Once we've made our custom calls to artifactory, we can use the built-in chef resource for remote_file to actually fetch the artifact
def download(remote_file_url)
# construct the filename and destination for remote file
remote_file_name = "#{new_resource.name}-#{new_resource.version}.#{new_resource.filetype}"
remote_file_destination = new_resource.artifact_target || ::File.join(Chef::Config[:file_cache_path], remote_file_name)
# construct the remote_file source
sha256_cksum = get_checksum(remote_file_url, "sha256")
Chef::Log.debug("checking sha256 checksum for #{new_resource.name}:#{sha256_cksum.inspect}")
@sbates
sbates / gist:4404905
Last active December 10, 2015 07:58
Artifactory sha-256 plugin being used to avoid remote_file repeated downloads
[2012-12-29T00:11:15-06:00] INFO: Processing artifact[solr] action download_static (solr::install line 46)
[2012-12-29T00:11:16-06:00] DEBUG: checking sha256 checksum for solr:"bb4415d1170ac94aa6bf065627617232ee94099ba3570b5c6bb9ca7cff30dca8"
[2012-12-29T00:11:16-06:00] INFO: Processing remote_file[/var/chef/cache/solr-4.0.0.war] action create (dynamically defined)
[2012-12-29T00:11:16-06:00] DEBUG: remote_file[/var/chef/cache/solr-4.0.0.war] checking for changes
[2012-12-29T00:11:16-06:00] DEBUG: remote_file[/var/chef/cache/solr-4.0.0.war] checksum matches target checksum (bb4415d1170ac94aa6bf065627617232ee94099ba3570b5c6bb9ca7cff30dca8) - not updating
@sbates
sbates / error
Created December 28, 2012 22:37
getting a chef error right after starting converge
Generated at 2012-12-28 16:33:15 -0600
ArgumentError: You must have a string like resource_type[name]!
/opt/chef/embedded/lib/ruby/gems/1.9.1/gems/chef-10.16.4/lib/chef/resource_collection.rb:205:in `find_resource_by_string'
/opt/chef/embedded/lib/ruby/gems/1.9.1/gems/chef-10.16.4/lib/chef/resource_collection.rb:139:in `block in find'
/opt/chef/embedded/lib/ruby/gems/1.9.1/gems/chef-10.16.4/lib/chef/resource_collection.rb:134:in `each'
/opt/chef/embedded/lib/ruby/gems/1.9.1/gems/chef-10.16.4/lib/chef/resource_collection.rb:134:in `find'
/opt/chef/embedded/lib/ruby/gems/1.9.1/gems/chef-10.16.4/lib/chef/resource.rb:61:in `fix_resource_reference'
/opt/chef/embedded/lib/ruby/gems/1.9.1/gems/chef-10.16.4/lib/chef/resource.rb:50:in `resolve_resource_reference'
/opt/chef/embedded/lib/ruby/gems/1.9.1/gems/chef-10.16.4/lib/chef/resource.rb:406:in `block in resolve_notification_references'
/opt/chef/embedded/lib/ruby/gems/1.9.1/gems/chef-10.16.4/lib/chef/resource.rb:406:in `each'
@sbates
sbates / gist:4383417
Created December 26, 2012 22:03
I notice so many people forking and rewriting cookbooks mostly because of installation diffs and we keep a lot of stuff in Artifactory. I'd like to be able to write Chef::Provider::Package::Artifactory and insert my custom package line instead of re-writing the wheel.
package "foo" do
action :install
end
# but I'm wondering about
package "foo" do
action :install
provider node[:foo][:provider]
end