Crates.io | ssh-to-ansible |
lib.rs | ssh-to-ansible |
version | 0.4.0 |
source | src |
created_at | 2023-11-11 07:58:55.267485 |
updated_at | 2024-09-15 08:48:26.897384 |
description | A tool to convert a SSH configuration to an Ansible YAML inventory. |
homepage | https://github.com/marccarre/ssh-to-ansible |
repository | https://github.com/marccarre/ssh-to-ansible |
max_upload_size | |
id | 1031917 |
size | 90,915 |
A tool to convert a SSH configuration to an Ansible YAML inventory.
brew install marccarre/homebrew-ssh-to-ansible/s2a
Or
brew tap marccarre/homebrew-ssh-to-ansible
brew install s2a
Or download from the release page and install manually at your convenience.
Provide any SSH configuration as an input to s2a
, either via stdin
or as an
input file, optionally define the name of the environment (-e
/--environment
)
for the Ansible inventory, and optionally provide an output YAML file.
s2a
works with any well-formed SSH configuration, e.g.:
cat ~/.ssh/config | s2a
vagrant ssh-config | s2a
By default, s2a
defaults the environment to be local
, reads from stdin
and
writes to stdout
:
$ cat <<EOF | s2a
Host default
HostName 127.0.0.1
User vagrant
Port 50022
UserKnownHostsFile /dev/null
StrictHostKeyChecking no
PasswordAuthentication no
IdentityFile /Users/me/.vagrant/machines/default/qemu/private_key
IdentitiesOnly yes
LogLevel FATAL
PubkeyAcceptedKeyTypes +ssh-rsa
HostKeyAlgorithms +ssh-rsa
EOF
local:
hosts:
default:
ansible_host: 127.0.0.1
ansible_port: 50022
ansible_user: vagrant
ansible_ssh_private_key_file: /Users/me/.vagrant/machines/default/qemu/private_key
ansible_ssh_extra_args: -o HostKeyAlgorithms=+ssh-rsa -o IdentitiesOnly=yes -o LogLevel=FATAL -o PasswordAuthentication=no -o PubkeyAcceptedKeyTypes=+ssh-rsa -o StrictHostKeyChecking=no -o UserKnownHostsFile=/dev/null
$ cat <<EOF | s2a -e dev
Host default
HostName 127.0.0.1
User vagrant
Port 50022
UserKnownHostsFile /dev/null
StrictHostKeyChecking no
PasswordAuthentication no
IdentityFile /Users/me/.vagrant/machines/default/qemu/private_key
IdentitiesOnly yes
LogLevel FATAL
PubkeyAcceptedKeyTypes +ssh-rsa
HostKeyAlgorithms +ssh-rsa
EOF
dev:
hosts:
default:
ansible_host: 127.0.0.1
ansible_port: 50022
ansible_user: vagrant
ansible_ssh_private_key_file: /Users/me/.vagrant/machines/default/qemu/private_key
ansible_ssh_extra_args: -o HostKeyAlgorithms=+ssh-rsa -o IdentitiesOnly=yes -o LogLevel=FATAL -o PasswordAuthentication=no -o PubkeyAcceptedKeyTypes=+ssh-rsa -o StrictHostKeyChecking=no -o UserKnownHostsFile=/dev/null
vars
in the Ansible inventoryProvide colon-separated key:value
pairs using the --var
CLI option:
$ cat <<EOF | ./s2a --var become:true --var http_port:"'8080'" --var num_workers:4 --var user:root
Host default
HostName 127.0.0.1
User vagrant
Port 50022
UserKnownHostsFile /dev/null
StrictHostKeyChecking no
PasswordAuthentication no
IdentityFile /Users/me/.vagrant/machines/default/qemu/private_key
IdentitiesOnly yes
LogLevel FATAL
PubkeyAcceptedKeyTypes +ssh-rsa
HostKeyAlgorithms +ssh-rsa
EOF
local:
hosts:
default:
ansible_host: 127.0.0.1
ansible_port: 50022
ansible_user: vagrant
ansible_ssh_private_key_file: /Users/me/.vagrant/machines/default/qemu/private_key
ansible_ssh_extra_args: -o HostKeyAlgorithms=+ssh-rsa -o IdentitiesOnly=yes -o LogLevel=FATAL -o PasswordAuthentication=no -o PubkeyAcceptedKeyTypes=+ssh-rsa -o StrictHostKeyChecking=no -o UserKnownHostsFile=/dev/null
vars:
become: true
http_port: '8080'
num_workers: 4
user: root
stdin
$ cat <<EOF > ssh_config
Host default
HostName 127.0.0.1
User vagrant
Port 50022
UserKnownHostsFile /dev/null
StrictHostKeyChecking no
PasswordAuthentication no
IdentityFile /Users/me/.vagrant/machines/default/qemu/private_key
IdentitiesOnly yes
LogLevel FATAL
PubkeyAcceptedKeyTypes +ssh-rsa
HostKeyAlgorithms +ssh-rsa
EOF
$ s2a -i ssh_config
local:
hosts:
default:
ansible_host: 127.0.0.1
ansible_port: 50022
ansible_user: vagrant
ansible_ssh_private_key_file: /Users/me/.vagrant/machines/default/qemu/private_key
ansible_ssh_extra_args: -o HostKeyAlgorithms=+ssh-rsa -o IdentitiesOnly=yes -o LogLevel=FATAL -o PasswordAuthentication=no -o PubkeyAcceptedKeyTypes=+ssh-rsa -o StrictHostKeyChecking=no -o UserKnownHostsFile=/dev/null
stdout
$ cat <<EOF | s2a -o local.yaml
Host default
HostName 127.0.0.1
User vagrant
Port 50022
UserKnownHostsFile /dev/null
StrictHostKeyChecking no
PasswordAuthentication no
IdentityFile /Users/me/.vagrant/machines/default/qemu/private_key
IdentitiesOnly yes
LogLevel FATAL
PubkeyAcceptedKeyTypes +ssh-rsa
HostKeyAlgorithms +ssh-rsa
EOF
$ cat local.yaml
local:
hosts:
default:
ansible_host: 127.0.0.1
ansible_port: 50022
ansible_user: vagrant
ansible_ssh_private_key_file: /Users/me/.vagrant/machines/default/qemu/private_key
ansible_ssh_extra_args: -o HostKeyAlgorithms=+ssh-rsa -o IdentitiesOnly=yes -o LogLevel=FATAL -o PasswordAuthentication=no -o PubkeyAcceptedKeyTypes=+ssh-rsa -o StrictHostKeyChecking=no -o UserKnownHostsFile=/dev/null
$ s2a --help
A tool to convert a SSH configuration to an Ansible YAML inventory.
Usage: s2a [OPTIONS]
Options:
-v, --verbose...
Increase logging verbosity
-q, --quiet...
Decrease logging verbosity
-e, --environment <ENVIRONMENT>
Name of the environment to generate [default: local]
--var <VARS>
Ansible variables to add to the hosts, as colon-separated name:value pair, e.g., --var new_ssh_port:22222 --var swap_size:3G
-i, --input-filepath <INPUT_FILEPATH>
Path of the input SSH configuration to parse [default: stdin]
-o, --output-filepath <OUTPUT_FILEPATH>
Path of the output Ansible inventory file to generate [default: stdout]
-h, --help
Print help
-V, --version
Print version
brew install just
just setup
cargo build
just lint
cargo test
just cover
export VERSION="X.Y.Z" # N.B.: no "v" prefix!
git tag -a "${VERSION}" -m "${VERSION}"
git push origin --tags
cargo login
cargo publish --dry-run
cargo publish
Then update the Homebrew Tap at: https://github.com/marccarre/homebrew-ssh-to-ansible
N.B.: in case of release job failure, and a re-release, the tag can be deleted this way (warning: bad practice to delete tags):
git tag -d "${VERSION}"
git push origin --delete "${VERSION}"