Skip to main content

Generate ssh config file from Ansible inventory

Project description

PyPI version Pylint check PyPI pulish

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

ansible_inventory_to_ssh_config-1.1.2.tar.gz (8.3 kB view details)

Uploaded Source

Built Distribution

File details

Details for the file ansible_inventory_to_ssh_config-1.1.2.tar.gz.

File metadata

File hashes

Hashes for ansible_inventory_to_ssh_config-1.1.2.tar.gz
Algorithm Hash digest
SHA256 3a8bf440c92836c8348643349477263c0532050cf9baa374b4631f8e12b2d08d
MD5 4605a5fe25b27bdc2ede390e748c082d
BLAKE2b-256 2a100ff409b9856d32a5b263f04a25c7d8d5d04b3596cdd1ce67cc5592e3b11d

See more details on using hashes here.

File details

Details for the file ansible_inventory_to_ssh_config-1.1.2-py3-none-any.whl.

File metadata

File hashes

Hashes for ansible_inventory_to_ssh_config-1.1.2-py3-none-any.whl
Algorithm Hash digest
SHA256 bc9fb87560c93dc9ecae2fb09a378c031e9f2500159b2e5fd65a73ce65349bf2
MD5 8a4625493eacd44364d4c943381735d5
BLAKE2b-256 07c7664682731f22835057b131b1c6e3ebefb56f8f5d2322cfa6656fc8223ee6

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page