Generate ssh config file from Ansible inventory
Project description
Ansible inventory file to ssh config
This is a Python tool for updating the SSH config from the Ansible inventory file.
Dependencies
Install
[!WARNING] This project would install Ansible with the specified version metioned above, be careful that might conflict with the version you are using currently. You might need a separated env for this tool, for example:
$ mkdir foo;cd foo foo$ pyenv virtualenv 3.11.4 bar;pyenv local bar (bar)foo$
$ pip install ansible-inventory-to-ssh-config
From Github:
$ pip install git+https://github.com/yioda/ansible-inventory-to-ssh-config
Local install
$ git clone https://github.com/yioda/ansible-inventory-to-ssh-config.git
$ pip install .
Usage
$ aitsc -h # or ansible-inventory-to-ssh-config -h
usage: aitsc [-h] [-v] [-o OUTPUT] [-d] [-b] [-O] inventory_file
positional arguments:
inventory_file ansible inventory file
options:
-h, --help show this help message and exit
-v, --version show program version number and exit
-o OUTPUT, --output OUTPUT
ssh config output path (default: ~/.ssh/config.ansible)
-d, --dry-run show new configurations without updating file
-b, --with-backup update with backup
-O, --override override whole config, this would remove those hosts undefined in playbook
# Update ~/.ssh/config.ansible from specified inventory file
$ aitsc $INVENTORY_FILE
# Update with backup
$ aitsc $INVENTORY_FILE --with-backup
# Output as a new file
$ aitsc $INVENTORY_FILE -o new_ssh_config
# Show content without output
$ aitsc $INVENTORY_FILE -d
# Override while config
$ aitsc $INVENTORY_FILE -O
Example
# Input (Inventory File)
$ cat hosts
[group_1]
node1 ansible_ssh_host=192.168.0.5
node2 ansible_ssh_host=192.168.0.6
[group_2]
node3 ansible_host=192.168.0.7 ansible_ssh_private_key_file=~/.ssh/id_rsa_for_ansible
node4 ansible_host=192.168.0.8 ansible_port=10422 ansible_user=foo
# Commnad
$ aitsc hosts -o newconfig
Inventory: hosts
Target: newconfig
# Output (SSH Config Format)
$ cat new_ssh_config
Host node1
HostName 192.168.0.5
Host node2
HostName 192.168.0.6
Host node3
HostName 192.168.0.7
IdentityFile ~/.ssh/id_rsa_for_ansible
Host node4
HostName 192.168.0.8
Port 10422
User foo
Project details
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
File details
Details for the file ansible_inventory_to_ssh_config-1.1.2.tar.gz
.
File metadata
- Download URL: ansible_inventory_to_ssh_config-1.1.2.tar.gz
- Upload date:
- Size: 8.3 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/5.1.0 CPython/3.12.5
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 3a8bf440c92836c8348643349477263c0532050cf9baa374b4631f8e12b2d08d |
|
MD5 | 4605a5fe25b27bdc2ede390e748c082d |
|
BLAKE2b-256 | 2a100ff409b9856d32a5b263f04a25c7d8d5d04b3596cdd1ce67cc5592e3b11d |
File details
Details for the file ansible_inventory_to_ssh_config-1.1.2-py3-none-any.whl
.
File metadata
- Download URL: ansible_inventory_to_ssh_config-1.1.2-py3-none-any.whl
- Upload date:
- Size: 5.8 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/5.1.0 CPython/3.12.5
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | bc9fb87560c93dc9ecae2fb09a378c031e9f2500159b2e5fd65a73ce65349bf2 |
|
MD5 | 8a4625493eacd44364d4c943381735d5 |
|
BLAKE2b-256 | 07c7664682731f22835057b131b1c6e3ebefb56f8f5d2322cfa6656fc8223ee6 |