Skip to content

Instantly share code, notes, and snippets.

View ScriptAutomate's full-sized avatar
:shipit:
Automating All The Things

Derek Ardolf ScriptAutomate

:shipit:
Automating All The Things
View GitHub Profile
@ScriptAutomate
ScriptAutomate / vagrant-rhel7-salt.sh
Last active August 27, 2021 21:56
Test salt on a RHEL7 vagrant box
##
# CONFIRMED WITH
# - Host OS: Pop!_OS 20.04 LTS
# - Vagrant v2.2.18
# - Box: generic/rhel7 v3.4.0
# - RHEL 7.9
# - Salt v3003.2
# - Virtualbox v6.1.18
#
# Last tested: 08/27/2021
@ScriptAutomate
ScriptAutomate / setup-macinbox-mojave.sh
Created August 19, 2021 00:26
Setup macinbox / MacOS Virtualbox VM via Vagrant on MacOS 10.14.x Mojave Host
# ==Prereq==
# Download from app store:
# https://apps.apple.com/us/app/macos-mojave/id1398502828?mt=12
# Output file:
# /Applications/Install\ macOS\ Mojave.app
# On a Mac host, install macinbox
# This is if using VirtualBox for virtualization
# https://github.com/bacongravy/macinbox
sudo gem install macinbox
@ScriptAutomate
ScriptAutomate / fix_smartquotes.py
Created August 17, 2021 21:54
Fix smartquotes with pre-commit via local repo call
"""
Code that can be called by pre-commit to fix smart quotes
Add into .pre-commit-config.yaml
- repo: local
hooks:
- id: check-smart-quotes
description: Checks for and fixes smart quotes.
name: Check and fix smartquotes
@ScriptAutomate
ScriptAutomate / install-isolated-salt-opensuse.sh
Created August 7, 2021 00:02
Install isolated salt, from pip, directly onto OpenSUSE (includes if in containers)
# Tested via
# docker container run --rm -it opensuse/leap:15.3 /bin/bash
# Check if in container
# https://stackoverflow.com/questions/52065842/python-docker-ascii-codec-cant-encode-character
if [ -f /.dockerenv ]; then
echo "Running in container. Setting LANG=C.UTF-8 locale..."
export LANG=C.UTF-8
fi
@ScriptAutomate
ScriptAutomate / git-delete-fat-files.md
Created August 6, 2021 23:31
Git: Delete fat files
# Remove the file, but also ensure it is wiped out
# entirely from the repo
git rm --cached --ignore-unmatch <file-in-repo>
@ScriptAutomate
ScriptAutomate / aws-sam-cli.sls
Last active August 27, 2021 21:43
Install SAM (Serverless Application Model) CLI via Salt State
{% set user_name = salt['pillar.get']('common:lookup:user') %}
aws-sam-cli-extract:
archive.extracted:
- name: /home/{{ user_name }}/Downloads/aws-sam-cli
- if_missing: /home/{{ user_name }}/Downloads/aws-sam-cli/install
- archive_format: zip
- enforce_toplevel: false
- source: https://github.com/aws/aws-sam-cli/releases/latest/download/aws-sam-cli-linux-x86_64.zip
- user: {{ user_name }}
- group: {{ user_name }}
@ScriptAutomate
ScriptAutomate / docker.sls
Last active August 27, 2021 21:39
Install docker, via salt, from official repos
# Created this state as part of the following:
# PR on salt-jenkins: https://github.com/saltstack/salt-jenkins/pull/1714
# Related issue in salt: https://github.com/saltstack/salt/issues/60605
{%- set on_docker = salt['grains.get']('virtual_subtype', '') in ('Docker',) %}
{%- set install_from_docker_repos = True if (grains['os_family'] == 'Debian' and grains['osarch'] in ('amd64', 'armhf', 'arm64') and grains['osmajorrelease'] != 11) or grains['os'] in ('AlmaLinux', 'CentOS', 'CentOS Stream', 'Fedora') else False %}
{%- if on_docker == False %}
include:
- busybox
{%- endif %}
@ScriptAutomate
ScriptAutomate / pyenv-root.sls
Last active August 27, 2021 21:45
Install pyenv in root home on container
# Prereqs recommended for building Python
## ref: https://github.com/pyenv/pyenv/wiki#suggested-build-environment
## Ubuntu/Debian/Mint (includes Pop!_OS, Kali, etc.)
pyenv-prereq-pkgs:
pkg.installed:
- pkgs:
- git
- make
- build-essential
- libssl-dev
@ScriptAutomate
ScriptAutomate / pyenv.sls
Last active March 5, 2022 11:45
Configure pyenv with salt state
# This is tested/verified on Pop!_OS 20.04 and 20.10
# Older versions tested on Parrot OS 4.1.0
# This example state requires common:lookup:user value in a pillar file
{% set user_name = salt['pillar.get']('common:lookup:user') %}
# Prereqs recommended for building Python
## ref: https://github.com/pyenv/pyenv/wiki#suggested-build-environment
## Ubuntu/Debian/Mint (includes Pop!_OS, Kali, etc.)
pyenv-prereq-pkgs:
pkg.installed:
@ScriptAutomate
ScriptAutomate / replacer.py
Last active August 27, 2021 21:48
Replace literal strings in files via Python
"""
Replace tool
Source: https://superuser.com/questions/422459/substitution-in-text-file-without-regular-expressions
"""
import re
import sys
search_term = sys.argv[1]
replace_term = sys.argv[2]
target_file = sys.argv[3]