master
1#!/usr/bin/env python
2# -h for usage
3# translates from standard ssh arguments into an ansible playbook host line
4# still pretty basic, no error handling etc
5
6# example 1 > user@host -p 22 -i /path/to/key
7# example 2 > host -l user -i /path/to/key
8
9import argparse
10parser = argparse.ArgumentParser()
11parser.add_argument("host")
12parser.add_argument("-l","--user")
13parser.add_argument("-p","--port", type=int)
14parser.add_argument("-i","--keyfile")
15args = parser.parse_args()
16
17hostsplit = args.host.split("@")
18if (len(hostsplit)==2):
19 user = hostsplit[0]
20 host = hostsplit[1]
21else:
22 user = args.user
23 host = args.host
24
25line = host + " ansible_connection=ssh"
26if (user): line = line + " ansible_ssh_user="+user
27if (args.keyfile): line = line + " ansible_ssh_private_key_file="+args.keyfile
28if (args.port): line = line + " ansible_ssh_port="+str(args.port)
29
30print line