diff options
-rw-r--r-- | bin/COMPLETION_SETUP | 21 | ||||
-rw-r--r-- | bin/ansibleutil.py | 4 | ||||
-rwxr-xr-x | bin/ossh (renamed from bin/ossh.py) | 9 | ||||
-rwxr-xr-x | bin/ossh_bash_completion | 18 |
4 files changed, 47 insertions, 5 deletions
diff --git a/bin/COMPLETION_SETUP b/bin/COMPLETION_SETUP new file mode 100644 index 000000000..c11a2dfff --- /dev/null +++ b/bin/COMPLETION_SETUP @@ -0,0 +1,21 @@ +# ossh is an ssh replacement. + +Ossh uses a dynamic inventory cache in order to lookup hostnames and translate them +to something meaningful such as an IP address or dns name. + +This allows us to treat our servers as cattle and not as pets. + +In order to setup bash completion, source the following script: +/path/to/repository/openshift-online-ansible/bin/ossh_bash_completion + +This bash_completion script will look at the cached version of your +multi_ec2 results in ~/.ansible/tmp/. It will then parse a few +host.env out of the json and return them to be completable. + +If you have not run the ossh command and it has not laid down +a cache file the completions will not be available. + +You can populate the cache by running `ossh --list`. This +will populate the cache file and the completions should +become available. + diff --git a/bin/ansibleutil.py b/bin/ansibleutil.py index 26fb25493..ed35ef8f9 100644 --- a/bin/ansibleutil.py +++ b/bin/ansibleutil.py @@ -57,10 +57,6 @@ class AnsibleUtil(object): for dns, host in inv['_meta']['hostvars'].items(): if host['ec2_tag_environment'] not in inst_by_env: inst_by_env[host['ec2_tag_environment']] = {} - - #if inst_by_env[host['ec2_tag_environment']][host['ec2_tag_Name']]: - #raise Exception('Duplicate ec2_tag_Name found: %s' % host['ec2_tag_Name']) - host_id = "%s:%s" % (host['ec2_tag_Name'],host['ec2_id']) inst_by_env[host['ec2_tag_environment']][host_id] = host @@ -25,6 +25,11 @@ class Ossh(object): def __init__(self): self.file_path = os.path.join(os.path.dirname(os.path.realpath(__file__))) self.parse_cli_args() + + if self.args.host == '' and not self.args.list: + self.parser.print_help() + return + self.ansible = ansibleutil.AnsibleUtil() self.host_inventory = self.get_hosts() @@ -57,7 +62,6 @@ class Ossh(object): action="store_true", help="Verbose?") parser.add_argument('--list', default=False, action="store_true", help="list out hosts") - parser.add_argument('host') parser.add_argument('-c', '--command', action='store', help='Command to run on remote host') parser.add_argument('-l', '--login_name', action='store', @@ -66,8 +70,11 @@ class Ossh(object): parser.add_argument('-o', '--ssh_opts', action='store', help='options to pass to SSH.\n \ "-o ForwardX11 yes"') + parser.add_argument('host', nargs='?', default='') self.args = parser.parse_args() + self.parser = parser + def process_host(self): '''Determine host name and user name for SSH. diff --git a/bin/ossh_bash_completion b/bin/ossh_bash_completion new file mode 100755 index 000000000..0d0bdb0e6 --- /dev/null +++ b/bin/ossh_bash_completion @@ -0,0 +1,18 @@ +__ossh_known_hosts(){ + if [[ -f ~/.ansible/tmp/multi_ec2_inventory.cache ]]; then + /usr/bin/python -c 'import json,os; z = json.loads(open("%s"%os.path.expanduser("~/.ansible/tmp/multi_ec2_inventory.cache")).read()); print "\n".join(["%s.%s" % (host["ec2_tag_Name"],host["ec2_tag_environment"]) for dns, host in z["_meta"]["hostvars"].items()])' + fi +} + +_ossh() +{ + local cur prev known_hosts + COMPREPLY=() + cur="${COMP_WORDS[COMP_CWORD]}" + prev="${COMP_WORDS[COMP_CWORD-1]}" + known_hosts="$(__ossh_known_hosts)" + COMPREPLY=( $(compgen -W "${known_hosts}" -- ${cur})) + + return 0 +} +complete -F _ossh ossh |