Messing around with knife exec
SEARCH='chef_environment:*dev*' knife exec partial_search.rb
# - name: node-a
# hostname: node-a
# fqdn: node-a.domain.net
# ipaddress: 10.190.116.124
# run_list:
# - role[base_os]
require 'chef' | |
def config_chef | |
chef_config_env_var = 'CHEF_CONFIG' | |
if ENV[chef_config_env_var] | |
chef_config = ENV[chef_config_env_var] | |
else | |
default_chef_configs = ['~/.chef/knife.rb', '/etc/chef/client.rb'] | |
default_chef_configs.each do |c| | |
if File.exists?(File.expand_path(c)) |
Messing around with knife exec
SEARCH='chef_environment:*dev*' knife exec partial_search.rb
# - name: node-a
# hostname: node-a
# fqdn: node-a.domain.net
# ipaddress: 10.190.116.124
# run_list:
# - role[base_os]
#!/bin/sh | |
# WARNING: REQUIRES /bin/sh | |
# | |
# - must run on /bin/sh on solaris 9 | |
# - must run on /bin/sh on AIX 6.x | |
# | |
# Copyright:: Copyright (c) 2010-2015 Chef Software, Inc. | |
# License:: Apache License, Version 2.0 | |
# | |
# Licensed under the Apache License, Version 2.0 (the "License"); |
Deep merge hashes. If both values are numeric they are summed.
$ ruby deep_sum_merge.rb
source:
layer_1: 10
deeper:
layer_2: 20
deeper:
layer_3: 30
deeper:
class Hash | |
def to_java_properties_hash(prefix='') | |
properties = {} | |
self.each do |property, value| | |
new_prefix = prefix.empty? ? property.to_s : prefix + '.' + property.to_s | |
if value.respond_to? :to_java_properties_hash | |
properties.merge!(value.to_java_properties_hash(new_prefix)) | |
else | |
properties[new_prefix] = value.to_s |
require 'chefspec' | |
module SpecHelper | |
def global_stubs | |
# Don't worry about external cookbook dependencies | |
Chef::Cookbook::Metadata.any_instance.stub(:depends) | |
# Test each recipe in isolation, regardless of includes | |
@included_recipes = [] | |
Chef::RunContext.any_instance.stub(:loaded_recipe?).and_return(false) |
# test_cookbook/recipes/default.rb | |
include_recipe 'test_cookbook::included_recipe' | |
include_recipe 'apt' | |
# test_cookbook/spec/recipes/default_spec.rb | |
describe 'test_cookbook::default' do | |
before(:all) { @included_recipes = [] } | |
before do | |
@stubbed_recipes = %w[test_cookbook::included_recipe apt] |
$ echo_and_run() { echo "$(date +%T) $*"; $*; } | |
$ echo_and_run ls | |
# 15:09:35 ls | |
# Gemfile Gemfile.lock README.md spec |
Description: > | |
Builds a basic /24 2x2 VPC (Public/Private, 2 AZs). The VPC CIDR block is determined by a combination | |
of the account ID and Region, giving a _very strong_ probability of a unique range within an | |
Organization. | |
Parameters: | |
VpcNameTag: | |
Type: String | |
Default: 2x2 | |
VpcCidrSuffix: |
#!/bin/bash | |
# | |
# Assume the given role, and print out a set of environment variables | |
# for use with aws cli. | |
# | |
# To use: | |
# | |
# $ eval $(./iam-assume-role.sh) | |
# |