Skip to content

Instantly share code, notes, and snippets.

View dougireton's full-sized avatar

Doug Ireton dougireton

View GitHub Profile
# https://github.com/opscode-cookbooks/windows
# create a printer
windows_printer 'HP LaserJet 5th Floor' do
driver_name 'HP LaserJet 4100 Series PCL6'
ipv4_address '10.4.64.38'
end
# include Windows::Helper from Opscode Windows Cookbook
::Chef::Recipe.send(:include, Windows::Helper)
# now you can call helper methods like win_friendly_path directly
my_batch_file = win_friendly_path(
::File.join( node['cookbook']['batch_dir'],'foo.bat'))
execute "My batch file" do
command my_batch_file
creates "e:/logs/my_batch_file.log"
locate_sysnative_cmd("dism.exe")
# include Windows::Helper from Opscode Windows Cookbook
::Chef::Recipe.send(:include, Windows::Helper)
# now you can call helper methods like win_friendly_path directly
my_batch_file = win_friendly_path(
::File.join( node['cookbook']['batch_dir'],'foo.bat'))
execute "My batch file" do
command my_batch_file
creates "e:/logs/my_batch_file.log"
Ohai::Config[:disabled_plugins] = [
# The following plugins are disabled as they are either not needed,
# have poor performance, or do not apply to the Windows configuration
# we use.
"c", "cloud", "ec2", "rackspace", "eucalyptus", "command", "dmi",
"dmi_common", "erlang", "groovy", "ip_scopes", "java", "keys",
"lua", "mono", "network_listeners", "passwd", "perl",
"php", "python", "ssh_host_key", "uptime", "virtualization",
"windows::virtualization", "windows::kernel_devices"
chef_gem "chef-vault"
require 'chef-vault'
# given a 'passwords' data bag
vault = ChefVault.new("passwords")
# get the 'Administrator' data bag item
user = vault.user("Administrator")
# https://github.com/moserke/diskpart-cookbook
diskpart_partition "create_#{disk[:letter]}:/" do
disk_number disk[:number]
align disk[:align]
letter disk[:letter]
action :create
end
diskpart_partition "format_#{disk[:letter]}:/" do
@dougireton
dougireton / chef.vim
Created February 8, 2013 06:25
(Broken) chef Syntastic syntax checker
function! SyntaxCheckers_chef_IsAvailable()
return executable('foodcritic')
endfunction
function! SyntaxCheckers_chef_GetLocList()
" let exe = expand(g:syntastic_ruby_exec)
" if !has('win32')
" let exe = 'RUBYOPT= ' . exe
" endif
@dougireton
dougireton / pre-commit
Created December 11, 2012 05:22
git pre-commit hook for linting Chef cookbooks
#!/usr/bin/env ruby
# check for whitespace errors
git_ws_check = `git diff-index --check --cached HEAD --`
unless $?.success?
puts git_ws_check
exit 1
end
COOKBOOK_PATH = File.split `git rev-parse --show-toplevel`
@dougireton
dougireton / chefspec_windows_rights_attributes
Created October 1, 2012 20:56
Chefspec doesn't seem to support Windows 'rights' attributes
When I run this spec, I get errors saying undefined method `rights' for Chef::Resource::CookbookFile since I'm using the [Windows 'rights' attribute](http://wiki.opscode.com/display/chef/Improved+Windows+File+Security)
Does chefspec support the Windows 'rights' attribute?
```ruby
require 'chefspec'
describe 'hosts_file::windows' do