-
-
Save gnosek/7774411 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python | |
from ansible.inventory import Inventory | |
import os | |
import sys | |
def get_addr(hostname): | |
inv = Inventory() | |
host = inv.get_host(hostname) | |
if not host: | |
return | |
vars = host.get_variables() | |
return vars.get('ansible_ssh_host', hostname) | |
if __name__ == '__main__': | |
ip = get_addr(sys.argv[1]) | |
if ip is None: | |
print >>sys.stderr, 'Unknown host' | |
sys.exit(1) | |
os.execvp('ssh', tuple(['ssh', ip, '-l', 'root'] + sys.argv[2:])) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment