ASH — Ansible SSH helper

Rimantas Ragainis
1 min readAug 16, 2019

By building your Ansible IT fleet up to several dozens of servers with various SSH credentials & settings to connect to, it’s getting annoyed routine to copy-paste needed data (IP, login user, port, etc.) from hosts file just to connect to server manually time after time:

$ ssh centos@X.X.X.X -i ~/.ssh/ansible

It’s really time-consuming process.. Wouldn’t be great to have a tool with some auto-completion? Heck yeah! But wait, isn’t there a tool for that already? It is, kind of — I found 6 years-old (last commit almost 1 year old) Github project as a layer of auto-completion for ansible commands/options. Ok.. but our goal is to have SSH helper literally to connect via terminal and use shell natively, e.g.:

$ ash m<TAB><TAB>
monitoring_server ms_jenkins ms_msisdn ms_vault
$ ash mo<TAB>
$ ash monitoring_server
Last login: Fri Aug 16 15:10:56 2019 from XXX
root@monitor:~#

So in order to achieve this, we need the code (later on) and modify shell profile whichever is preferred: ~/.profile, ~/.bash_profile, ~/.bashrc, ~/.zshrc, etc.:

# ash - Ansible SSH Helper tool
source <absolute_path>/ash
# note for MacOS & zsh
autoload compinit bashcompinit && compinit && bashcompinit && source <absolute_path>/ash

And here’s the code for that.

Notes:
- jq support is needed
- hosts file must be located at the same directory as the ash script

--

--