Metadata-Version: 2.4
Name: ssh_ansible
Version: 0.9.0
Summary: SSH to host from ansible inventory
Home-page: https://github.com/marekruzicka/ansible-ssh.git
Author: Marek Ruzicka
Author-email: pypi@glide.sk
License: MIT
Classifier: Development Status :: 4 - Beta
Classifier: Programming Language :: Python :: 3
Classifier: License :: OSI Approved :: MIT License
Classifier: Operating System :: POSIX :: Linux
Classifier: Environment :: Console
Description-Content-Type: text/markdown
License-File: LICENSE
Requires-Dist: ansible-core>=2.9
Dynamic: author
Dynamic: author-email
Dynamic: classifier
Dynamic: description
Dynamic: description-content-type
Dynamic: home-page
Dynamic: license
Dynamic: license-file
Dynamic: requires-dist
Dynamic: summary

# ssh-ansible

**ansible-ssh** *(name of the actual binary)* is a command-line utility that enables SSH connection to a host, utilizing connection variables retrieved from an Ansible inventory file.  
It provides user-friendly bash command completion (inlcuding completing hosts from Ansible inventory file).
It supports connection details (such as host, port, user, key, and even password). Extra SSH options via `ansible_ssh_common_args` and `ansible_ssh_extra_args` are *still experimental and not working properly*.

## Features

Simply run  `ansible-ssh -i inventory <host>`

- **Automated Connection Parameters:** Extracts connection details from an Ansible inventory.
- **Fallback Mechanism:** Uses standard SSH configuration (e.g., `~/.ssh/config`) for any unspecified settings.
- **Bash Completion:** Generates a bash completion script that auto-completes host names based on your inventory.
- **Extra SSH Options:** Incorporates additional SSH arguments defined in your inventory. (disabled for now)

## Requirements

- **Python3**
- **Ansible:** Required for running `ansible-inventory`.
- **sshpass:** (Optional) Required for password-based SSH connections.
- **bash-completion:** This is pretty much 50% of the functionality.
- **jq:** Required for parsing JSON output in the bash completion script.


## Installation
### pip
Create or activate virtual env, install it using `pip`, and install bash completion script.
```bash
# Create, activate python virtual environment
virtualenv myvenv
source myvenv/bin/activate

# Install package using pip (yes pypi package has the name reversed)
pip install ssh-ansible

# Generate bash_completion script
ansible-ssh -C bash | sudo tee /etc/bash_completion.d/ansible-ssh
source /etc/bash_completion.d/ansible-ssh
```


## Usage
```bash
$ ansible-ssh --help
usage: ansible-ssh.py [-h] [-C {bash}] [-i INVENTORY] [host] [--print-only] [--debug]

Connect to a host using connection variables from an Ansible inventory.

positional arguments:
  host                  Host to connect to

options:
  -h, --help            show this help message and exit
  -C {bash}, --complete {bash}
                        Print bash completion script and exit
  -i INVENTORY, --inventory INVENTORY
                        Path to the Ansible inventory file
  --print-only          Print SSH command instead of executing it
  --debug               Increase verbosity (can be used up to 3 times)

EXAMPLES:
  Connect to a host:
         ansible-ssh.py -i inventory myhost

  Connect to a host with ssh verbosity:
         ansible-ssh.py -i inventory myhost --debug --debug

  Print SSH command:
         ansible-ssh.py -i inventory myhost --print-only

  Generate and install bash completion script:
         ansible-ssh.py -C bash | sudo tee /etc/bash_completion.d/ansible-ssh.py

```
