Skip to content

Instantly share code, notes, and snippets.

View jmassardo's full-sized avatar

Jenna Massardo jmassardo

  • GitHub Staff
  • Monett, MO
View GitHub Profile
@jmassardo
jmassardo / EmailNodeCount-SendGrid.sh
Created August 14, 2018 19:32
Simple script to email Chef Server node counts via SendGrid
BU_NAME='The Awesome Group!'
NODE_COUNT="$(/path/to/chef-repo/knife exec -E "puts api.get('/nodes').size")"
MONTH="$(date +%B)"
YEAR="$(date +%Y)"
MAIL_URL="https://api.sendgrid.com/v3/mail/send"
HEADER="Authorization: Bearer My-Super-Secret-Token"
HEADER2="Content-Type: application/json"
EMAIL_TO='[email protected]'
EMAIL_FROM='[email protected]'
EMAIL_SUBJECT="Chef Server Node Count for ${BU_NAME}"
@jmassardo
jmassardo / RemoveStaleChefNodes.sh
Created August 21, 2018 13:53
Simple script to remove old nodes from a Chef Server
for node in $(knife search node "ohai_time:[* TO $(date +%s -d '30 days ago')]" -i); do
knife client delete $node
knife node delete $node
done
@jmassardo
jmassardo / MinimumChefAndAutomateInstall.sh
Last active August 27, 2018 18:45
Minimum steps needed to install Chef Server and Automate with data collector
#### Install Automate Server ###
# Set up pre-reqs
sysctl -w vm.max_map_count=262144
sysctl -w vm.dirty_expire_centisecs=20000
# Make them permenant
vi /etc/sysctl.conf
vm.max_map_count=262144
@jmassardo
jmassardo / CreateAzureSP.sh
Created December 12, 2018 14:19
Commands for creating an Azure Service Principal for Test Kitchen, Packer, Terraform, etc.
# Get a list of all the available subscriptions
az account list
# Output
#
#[
# {
# "cloudName": "AzureCloud",
# "id": "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx" <- Subscription ID
# "isDefault": true,
@jmassardo
jmassardo / Invoke-WebRequest_Ignore_SSL.ps1
Created February 26, 2019 15:19
PowerShell hack to ignore ssl certificates when using Invoke-WebRequest
add-type @"
using System.Net;
using System.Security.Cryptography.X509Certificates;
public class TrustAllCertsPolicy : ICertificatePolicy {
public bool CheckValidationResult(
ServicePoint srvPoint, X509Certificate certificate,
WebRequest request, int certificateProblem) {
return true;
}
}

Simple example of pushing the Chef Environment name over to Inspec

Control:

title 'Forwarders'

environments = yaml(content: inspec.profile.file('forwarders.yml')).params
chef_environment = attribute('chef_environment', description: 'The chef environment for the node', default: 'nope')
@jmassardo
jmassardo / WebhookTranslator.md
Last active February 26, 2019 18:19
This is a simple PowerShell hack to translate an incoming webhook from Github to MS Teams.

PowerShell hack to reformat webhook payload from GitHub to MS Teams. I run it as an Azure Function. This same concept will also work for other applications that send complex payloads via webhook.

Github Webhook -> Azure Function -> MS Teams Webhook.

# Accept the data from the incoming webhook.
param (
    [object]$WebhookData
)
az vm create -n hostname -g rgname --public-ip-address-allocation dynamic --image UbuntuLTS --size Standard_D4s_v3 --nsg nsgname --admin-username admin --admin-password password
@jmassardo
jmassardo / CountChefNodes.sh
Last active August 26, 2019 17:19
This script provides an easy way to count all the nodes in all the orgs on a Chef Server
# Make temp config.rb so we can ignore any ssl errors
echo "ssl_verify_mode :verify_none" > temp_config.rb
# Pull a list of all the orgs on the server
# then loop through each one and make an api call to get the node count
chef-server-ctl org-list -a | while read -r org ; do
echo "Attempting to connect to the $org organization."
/opt/opscode/embedded/bin/knife exec -E "puts api.get('/nodes').size" -s https://127.0.0.1/organizations/$org -u pivotal -k /etc/opscode/pivotal.pem --config temp_config.rb
done
@jmassardo
jmassardo / knife.rb
Created February 24, 2020 22:50
Sample knife.rb or config.rb for Chef
current_dir = File.dirname(__FILE__)
log_level :info
log_location STDOUT
node_name "YOUR_CHEF_SERVER_USERNAME"
client_key "#{current_dir}/#{node_name}.pem"
chef_server_url "https://CHEF_SERVER_FQDN/organizations/CHEF_ORG_SHORT_NAME"
cookbook_path ["#{current_dir}/../cookbooks"]
#ssl_verify_mode :verify_none