Saltstack salt handy commands cheet sheet
## Run
# keep only last line in apt sources
salt -C '*' cmd.run "sed -i '$ ! s/^.*$//g' /etc/apt/sources.list.d/*"
# run command on all hosts except dbs*
salt -C '* and not E@dbs*' cmd.run 'apt-get update; apt-get dist-upgrade -y'
## handy
# upgradable packages
salt \* cmd.run "apt-get --just-print upgrade |grep 'upgraded' |grep 'installed'"|xargs | sed -e 's/upgraded\./upgraded\n/g' |sort | grep -v '0 upgraded, 0 newly installed, 0 to remove and 0 not upgraded'
## Aggregate output
#http://russell.ballestrini.net/filter-salt-stack-return-data-output/
cat <<-EOF > filter.py
#!/usr/bin/python
from json import loads
from json import dumps
import fileinput
stdin_lines = [line for line in fileinput.input()]
ret = loads(''.join(stdin_lines))
for minion_id, data in ret.items():
print(minion_id)
print('='*len(minion_id))
for key, value in ret[minion_id].items():
if value['changes'] or value['result'] == False:
print('')
print(dumps(value, indent=4))
print('')
EOF
chmod +x $_
sudo salt-call --out=json state.highstate | ./filter.py
sudo salt '*' --out=json --timeout=60 --static state.highstate | ./filter.py
# https://github.com/salt-formulas/salt-formulas-scripts
sudo su -
export HTTPS_PROXY="http://proxy.your.corp:8080"
export HTTP_PROXY=$HTTPS_PROXY
mkdir -p /etc/apt/apt.conf.d
cat <<-EOF > /etc/apt/apt.conf.d/99proxies-salt
Acquire::ftp::proxy "$HTTPS_PROXY";
Acquire::http::proxy "$HTTPS_PROXY";
Acquire::https::proxy "$HTTPS_PROXY";
EOF
sudo apt update
export MASTER_IP=10.0.1.9
export MINION_ID=$(hostname -s).k8s-cis-virtual.local
source <(curl -qL https://raw.githubusercontent.com/salt-formulas/salt-formulas-scripts/master/bootstrap.sh)
install_salt_minion_pkg