crates.io version build status downloads Coverage Status
# ssh-to-ansible A tool to convert a SSH configuration to an Ansible YAML inventory. ## Installation ```console brew install marccarre/homebrew-ssh-to-ansible/s2a ``` Or ```console brew tap marccarre/homebrew-ssh-to-ansible brew install s2a ``` Or download from the [release](https://github.com/marccarre/ssh-to-ansible/releases) page and install manually at your convenience. ## Usage 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` ### Examples #### Default options By default, `s2a` defaults the environment to be `local`, reads from `stdin` and writes to `stdout`: ```console $ cat < #### Configure the Ansible inventory's environment ```console $ cat < #### Configure `vars` in the Ansible inventory Provide colon-separated `key:value` pairs using the `--var` CLI option: ```console $ cat < #### Read from input file instead of `stdin` ```console $ cat < 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 ``` #### Write to output file instead of `stdout` ```console $ cat < ### Help ```console $ 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 Name of the environment to generate [default: local] --var 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 Path of the input SSH configuration to parse [default: stdin] -o, --output-filepath Path of the output Ansible inventory file to generate [default: stdout] -h, --help Print help -V, --version Print version ``` ## Development ### Setup ```console brew install just just setup ``` ### Build ```console cargo build ``` ### Lint ```console just lint ``` ### Test #### Unit tests ```console cargo test ``` #### Coverage ```console just cover ``` ### Release ```console 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: 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): ```console git tag -d "${VERSION}" git push origin --delete "${VERSION}" ```