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='name@example.com'
EMAIL_FROM='name@example.com'
EMAIL_SUBJECT="Chef Server Node Count for ${BU_NAME}"
@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

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
)
@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,
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
@jmassardo
jmassardo / ExcludeNamespace.rego
Created February 19, 2021 14:20
Simple Rego rule to exclude certain k8s namespaces
# List of namespaces to exclude
excludedNamespaces = {"good", "ok"}
imageSafety[decision] {
# This rule compares the namespace from the admission controller
# to the list of namespaces above
not excludedNamespaces[input.request.namespace]
data.library.v1.kubernetes.admission.workload.v1.block_latest_image_tag[message]
decision := {
@jmassardo
jmassardo / DASRuleCustomName.rego
Created February 19, 2021 14:21
Example of how to give a rule a custom name so it can be called individually from a unit test
# List of namespaces to exclude
excludedNamespaces = {"good", "ok"}
imageSafety[decision] {
# This rule compares the namespace from the admission controller
# to the list of namespaces above
not excludedNamespaces[input.request.namespace]
data.library.v1.kubernetes.admission.workload.v1.block_latest_image_tag[message]
decision := {