Skip to main content

Ansibleconnect - connect to all hosts from the inventory with one command

Ansible Version CI Status
2.7 Ansible 2.7 Build Status
2.8 Ansible 2.8 Build Status
2.9 Ansible 2.9 Build Status
2.10 Ansible 2.10 Build Status

SSH into all hosts in your inventory with one command.

Ansibleconnect creates a bash script based on your ansible inventory. That script will create a new tmux window or session and create a separate pane for each one of your 'sshable' inventory hosts. Inside of each of the panes an ssh connection to the pane's host will be established.

Setup example (on Ubuntu):

sudo apt install tmux
sudo apt install sshpass
pip install ansibleconnect

Usage examples:

Connect to all hosts in inventory:

source <(ansibleconnect -i inventory.yml)

Connect to all hosts from group1 and group2:

source <(ansibleconnect -i inventory.yml -g 'group1:group2')

Connect to all hosts from group1 except for hosts that are also in group2:

source <(ansibleconnect -i inventory.yml -g 'group1:!group2')

Connect to all hosts from inventory except for hosts in group1:

source <(ansibleconnect -i inventory.yml -g '!group1')

Connect to all hosts that have AWS provider:

source <(ansibleconnect -i inventory.yml -vars provider:aws)>

NOTE: In case you don't use bash. You can also use eval command, for example:

eval "$(ansibleconnect -i inventories/inventory.yml)"

Possible flags

  • -i, --inventory - Path to ansible inventory
  • -g, --groups - Inventory groups of hosts to connect to (multiple groups should be concentrated with :. ! in front of group name means that ansibleconnect should not connect to hosts form this group). Example: -g computes:!storage
  • --hosts - List of hostnames to connect to. Example: --hosts hostA,hostB
  • -vars, --variables - Variables that host should have defined in inventory to connect to it. Accepted format: key:value in case where host should have variable with specific value or key in case where host should have defined variable no matter what value. Example: -v type:dev,team:ui
  • -novars, --no-variables - Variables that host should not have defined in inventory to connect to it. Accepted format: key:value in case where host should not have variable with specific value or key in case where host should not have defined variable no matter what value.Example: -novars type:prod,team:sales
  • -w, --windows - If present, then the output tmux command will create new window for each host session instead of a new pane

Configuration

Ansibleconnect looks for the ansible.cfg file in the same locations as ansible.

Authentication

ssh-agent

For authentication one can use ssh keys. ansibleconnect will scan the inventory file for connection options (ansible_ssh_common_args, ansible_ssh_user, ansible_host, ansible_private_key_file, etc.). Ssh keys can be passed via them. Otherwise, one can use the ssh-agent tool. Environment args (SSH_AGENT_PID and SSH_AUTH_SOCK) will be passed to each one of the tmux shells.

ssh-agent setup example
eval $(ssh-agent)
ssh-add ~/.ssh/my_private_key.pem

sshpass

If ansible_ssh_pass variable is used in the inventory, one should install the sshpass and make it discoverable via PATH. Please note that when using the sshpass, password will passed in plaintext and it will be saved in each of the tmux shells' history.

Release files for ansibleconnect 1.1.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for ansibleconnect 1.1.0
File Size Uploaded
ansibleconnect-1.1.0.tar.gz 12.1 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for ansibleconnect 1.1.0
File Interpreter ABI Platform
ansibleconnect-1.1.0-py3-none-any.whl Python 3 none any Details

Total release size:22.1 kB

Release files / ansibleconnect-1.1.0.tar.gz

Download URL ansibleconnect-1.1.0.tar.gz
Size 12.1 kB
Tags Source
SHA-256 checksum
How to use checksums
615f483cd766240603ebdc85b62fdf745a6582fc757c7cc7c81d58c7236cc7bb
BLAKE2b-256 checksum
How to use checksums
222447aefa6b6680c1661c4dc1f2c8d937a5f10e7794b34ec0e3bd78d9be8e4b
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.0.1 CPython/3.12.7

Release files / ansibleconnect-1.1.0-py3-none-any.whl

Download URL ansibleconnect-1.1.0-py3-none-any.whl
Size 10.0 kB
Tags Python 3
SHA-256 checksum
How to use checksums
28a084809ae77e903e63e3ab99282c69fb0ee06e25f8c424f9e195d8b012d795
BLAKE2b-256 checksum
How to use checksums
340874c535b69162a9224bba948610fd981293afbebdda0e968025c67b91fd60
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.0.1 CPython/3.12.7

Release history Release notifications | RSS feed

This release

1.1.0 This release

2 release files

1.0.31

2 release files

1.0.4

2 release files

1.0.3

2 release files

1.0.2

2 release files

1.0.1

2 release files

1.0.0

2 release files

0.1.0

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page