Skip to content

Instantly share code, notes, and snippets.

View johnccfm's full-sized avatar

John Carlyle-Clarke johnccfm

  • Fastmarkets Limited
  • United Kingdom
View GitHub Profile
@johnccfm
johnccfm / pillar.sls
Created November 23, 2015 14:34
Saltstack pillar data assignment based on structured minion ID
#!py
import re
# Some hosts have legacy names so remap them here
known_hosts = {
r'^fmfa([0-9]+)($|\.)' : 'gr-prod-f-app-%1',
r'^fmpa([0-9]+)($|\.)' : 'gr-prod-p-app-%1',
}
$name = "web01"
$source = "https://repo.saltstack.com/windows/Salt-Minion-2015.8.0-3-AMD64-Setup.exe"
$dest = "$env:TMP\salt-minion.exe"
$client = new-object system.net.webclient
$client.DownloadFile($source, $dest)
& $dest /S /master=saltmaster.fmlocal /minion-name=$name
{'Third': '3', 'Second': '2', 'First': '1'}
{'Third': '6', 'Second': '5', 'First': '4'}
{'Third': '915,as', 'Second': '23', 'First': 'Foo'}
1
4
Foo
1 2 3
4 5 6
Foo 23 915,as
#!py
import re
known_hosts = {
r'^dns1($|\.)' : 'gr-prod-c-dns-1',
r'^mcp($|\.)' : 'gr-prod-c-mcp-1'
}
standard = """
@johnccfm
johnccfm / mysql-diff
Last active August 29, 2015 14:16
Compare and diff mysql config files
#!/bin/bash
extract-keys() {
<$1 sed 's/#.*//;s/[[:space:]]\+//;/^$/d;/^!/d' |
gawk -F= '!/^\[/ { print pref "." $1 "\t" $2 } match($0, /\[([^\]]*)\]/, m) { pref = m[1] }' |
sort
}
(printf "Key %s %s\n--- --- ---\n" $1 $2
join -a1 -a2 -o 0,1.2,2.2 -e. <(extract-keys $1) <(extract-keys $2) | awk '$2 != $3') | column -t