Skip to content

Instantly share code, notes, and snippets.

@andy-dufour
andy-dufour / keybase.md
Created April 10, 2018 17:50
keybase.md

Keybase proof

I hereby claim:

  • I am andy-dufour on github.
  • I am andy_dufour (https://keybase.io/andy_dufour) on keybase.
  • I have a public key ASCF2VniPppduj4Dc9U2f60VnHjKbuyqQedezmfKG6-BVgo

To claim this, I am signing this object:

@andy-dufour
andy-dufour / cleanup-missing-nodes.rb
Last active July 20, 2018 21:58
Cleanup missing nodes in Chef Automate
#!/opt/delivery/embedded/bin/ruby
require 'elasticsearch'
require 'json'
# Get the user configuration for the time threshold we will use to mark the
# nodes as missing. We read it from the delivery config if available, or use the
# environment variable which might be set or set it to the default of 12 hours.
threshold_in_mins = begin
if File.exist?("/etc/delivery/delivery-running.json")
e2fsck -f /dev/mapper/opscode-drbd
resize2fs /dev/mapper/opscode-drbd 5G

Place the contents of report-filler.rb into ~/report-filler.rb

ruby report-filler.rb &
def partner_server(name)
# takes a server name and returns the previous server if even
# the next server if odd
server = name.scan(/\d+/).first
length = server.length
number = server.to_i
if number.to_i.odd?
number += 1
else
number -= 1

Run: supermarket-ctl cleanse

Wait the 60 seconds.

mkdir -p /etc/supermarket

cleanse made a backup of your config in /root/supermarket-cleanse-2016-01-*

restore supermarket.rb from there to /etc/supermarket/

@andy-dufour
andy-dufour / supermarket-sles.MD
Last active January 5, 2016 07:39
Supermarket install on SLES11SP3

Commands:

rpm -Uvh supermarket-2.2.2-1.el6.x86_64.rpm

vi /opt/supermarket/embedded/cookbooks/sysctl/recipes/default.rb

At line 22 add the line node.default['sysctl']['conf_dir'] = '/etc/sysctl' :

include_recipe 'sysctl::service'
@andy-dufour
andy-dufour / compliance-sles.MD
Last active January 5, 2016 06:53
Compliance on SLES11SP3

Commands:

rpm -Uvh chef-compliance-0.9.6-1.el6.x86_64.rpm

vi /opt/chef-compliance/embedded/cookbooks/sysctl/recipes/default.rb

At line 22 add the line node.default['sysctl']['conf_dir'] = '/etc/sysctl':

include_recipe 'sysctl::service'

Creating a Custom Cookbook Generator

There are a few resources on the internet today about creating custom cookbook generators. The most popular is chef-gen-flavors.

These resources are generally pretty meta and slightly hard to understand, so I'm going to walk you through customizing a cookbook generator from the ground up. To do this we're going to start with a great generator called pan. After we customize the generators we're going to build the gem and install it locally.

One thing to know about chef-gen-flavors is that its heavily name based, so where-ever you see Pan and I'm replacing it with awesomesauce, you can replace with whatever the name of your flavor is, but it must be replaced in all of the same places.

Clone the repo

{
"chef.server.rabbitmq_messages_ready": 0,
"chef.server.postgresql_seq_scan": "45711",
"chef.server.postgresql_seq_tup_read": "2687721",
"chef.server.postgresql_idx_scan": "646701",
"chef.server.postgresql_idx_tup_fetch": "575829",
"chef.server.postgresql_n_tup_ins": "7304",
"chef.server.postgresql_n_tup_upd": "765",
"chef.server.postgresql_n_tup_del": "3009",
"chef.server.postgresql_n_live_tup": "13928",
#!/usr/bin/env escript
-define(ERCHEF, 'erchef@127.0.0.1').
-define(ERCHEF_COOKIE, 'erchef').
-define(SELF, 'chef-stats@127.0.0.1').
fetch_metric({MetricKey, [MetricType = {type, histogram}, _]}) ->
{MetricKey, rpc:call(?ERCHEF, folsom_metrics,get_histogram_statistics,[MetricKey]), MetricType};
fetch_metric({MetricKey, [MetricType, _]}) ->
{MetricKey, rpc:call(?ERCHEF, folsom_metrics,get_metric_value,[MetricKey]), MetricType}.