Skip to content

Instantly share code, notes, and snippets.

@fspot
Created October 10, 2013 00:58
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save fspot/6911309 to your computer and use it in GitHub Desktop.
Save fspot/6911309 to your computer and use it in GitHub Desktop.
Usage : "saltshell.py" to get the list of minions (+ os and ip), "saltshell.py foo" to virtually ssh into foo minion. A lot of restrictions. May not work if your salt master is properly configured.
#!/usr/bin/env python
# -*- coding:utf-8 -*-
import sys
import os
from os.path import join
if len(sys.argv) == 1:
print "\n### Wanna see the list of connected minions, and their respective OS ? k."
print "### Wait a little... like 10s...\n"
os.system("salt -v '*' grains.item os ipv4")
sys.exit(0)
print "\n### I suppose you're root, in /root."
print "### Do not trust that and test whoami and pwd. On Windows ? Ha-ha !"
print "### Also, don't forget : any command here does not affect next commands."
print "### So, forget 'source venv/bin/activate', 'export PATH=truc', 'screen -r', etc."
print "### Also, use only finishing-commands like ls or cat. Forget less, htop, vim, nano, screen, tail -f...\n"
dest = sys.argv[1]
rep = '/root'
while True:
cmd = raw_input('>>> root@%s:%s # ' % (dest, rep))
if cmd == 'cd':
cmd = 'cd /root'
if cmd.startswith('cd /') or cmd.startswith('cd ') and cmd[4] == ':':
rep = cmd[3:]
elif cmd.startswith('cd '):
rep = join(rep, cmd[3:])
else:
os.system("salt '%s' cmd.run 'cd %s && %s'" % (dest, rep, cmd))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment