Skip to content

Instantly share code, notes, and snippets.

@gnosek
Created December 3, 2013 18:12
Show Gist options
  • Save gnosek/7774411 to your computer and use it in GitHub Desktop.
Save gnosek/7774411 to your computer and use it in GitHub Desktop.
#!/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