Skip to content

Instantly share code, notes, and snippets.

View teknofire's full-sized avatar

Will Fisher teknofire

View GitHub Profile
@teknofire
teknofire / a2ha_fe_bundle.sh
Last active March 29, 2023 22:04
Custom Airgap bundle version generation for A2HA
#!/usr/bin/env bash
################################################################################
# This script will generate the necessary airgap bundles and configs for an A2HA
# Workstation to deploy a specific version of Automate on the FE nodes.
#
# By default this will upgrade an A2HA installation with Automate 20220310123121 which is
# latest version compatabile with A2HA.
#
# Installation:
id=$1
profile=$2
type=image # or "instance" or "volume" or "snapshot" or ...
regions=$(aws ec2 describe-regions --profile=$profile --output text --query 'Regions[*].RegionName')
for region in $regions; do
(
# need to test length of the return as it might have been deleted from the region
test $(aws ec2 describe-${type}s --profile=$profile --region $region --$type-ids $id | jq ".Images | length") -gt 0 &&
echo "$id is in $region"
# Place this file in ~/.chef/plugins/knife/ruby_version.rb
# Run by calling `knife ruby_version`
require 'chef/knife'
module RubyVersion
class RubyVersion < Chef::Knife
banner "knife ruby_version"
def run
{
"action": "*",
"resource": "*",
"subjects": [
"team:ldap:ldap-admins-group"
]
}
@teknofire
teknofire / custom_handler_reboot.rb
Created April 26, 2019 16:14
EventHandler reboot_pending?
class CustomRebootHelper
include Chef::DSL::RebootPending
attr_accessor :node
def initialize(node)
@node = node
end
end
Chef.event_handler do
@teknofire
teknofire / find_ami.sh
Created April 25, 2019 21:03
Find what region an AMI lives in
id=$1
profile=$2
type=image # or "instance" or "volume" or "snapshot" or ...
regions=$(aws ec2 describe-regions --profile=$profile --output text --query 'Regions[*].RegionName')
for region in $regions; do
(
aws ec2 describe-${type}s --profile=$profile --region $region --$type-ids $id &>/dev/null &&
echo "$id is in $region"
) &
[2018-11-21T01:42:49+00:00] ERROR: Object does not exist on remote server.
[2018-11-21T01:42:49+00:00] ERROR: Received HTTP error 404
[2018-11-21T01:42:49+00:00] ERROR: Report handler Chef::Handler::AuditReport raised #<RuntimeError: Unable to find requested profile on path: '/compliance/organizations/support/owners/admin/compliance/badprofile/tar' on the Automate system.>
[2018-11-21T01:42:49+00:00] ERROR: /var/chef/cache/cookbooks/audit/files/default/vendor/chef-server/fetcher.rb:102:in `download_archive_to_temp'
[2018-11-21T01:42:49+00:00] ERROR: /opt/chef/embedded/lib/ruby/gems/2.5.0/gems/inspec-core-2.2.102/lib/fetchers/url.rb:144:in `temp_archive_path'
[2018-11-21T01:42:49+00:00] ERROR: /opt/chef/embedded/lib/ruby/gems/2.5.0/gems/inspec-core-2.2.102/lib/fetchers/url.rb:124:in `sha256'
[2018-11-21T01:42:49+00:00] ERROR: /opt/chef/embedded/lib/ruby/gems/2.5.0/gems/inspec-core-2.2.102/lib/bundles/inspec-compliance/target.rb:30:in `sha256'
[2018-11-21T01:42:49+00:00] ERROR: /opt/chef/embedded/lib/ruby/gems/
@teknofire
teknofire / Output
Last active November 20, 2018 21:42
irb(main):034:0> a = "\x91" # Windows-1252 hex code for curly quote
=> "\x91"
irb(main):035:0> puts a
=> nil
irb(main):036:0> puts a.valid_encoding?
false
=> nil
irb(main):037:0> puts a.force_encoding('Windows-1252')
#!/opt/delivery/embedded/bin/ruby
# Usage:
# 1. download this file as automate_compare_status.rb
# 2. make it executable `chmod u+x find_missing_compliance_nodes.rb`
# 3. run the report `./find_missing_compliance_nodes.rb > missing_nodes_report.txt`
#
# This will print information to the console about the number of nodes found and
# how many are missing. It will filter out all nodes that doesn't have the
# wgb_audit::default recipe.
#
#!/opt/delivery/embedded/bin/ruby
require 'json'
require 'pp'
days = ARGV.first
days ||= 3
STDERR.puts "Fetching #{days} days of compliance indices"
all_indices = JSON.parse(`curl -s -k -XGET 'localhost:9200/_cat/indices?format=json'`)