Create a script to perform the following tasks:
- Retrieve Device Information
Fetch device details from NetBox. - Select Device
Display the retrieved devices usingfzf(a command-line fuzzy finder) for easy selection. - Fetch Credentials
Access the corresponding credentials for the selected device from Bitwarden. - Select Credential
Usefzfto display and choose the appropriate credential from the retrieved list. - Connect via SSH
Establish an SSH connection to the selected host through a jump host, using the chosen credentials (password-based authentication).
- sshpass - to use SSH interactive password in non-interactive manner
- bitwarden-cli - to get passwords
- jq - to get credential names from BitWarden
- nbcli - to get list of devices and addresses
- fzf - to provide choose interface for user
- ssh - to connect
- NOC host as a jumphost
- make sure that you have jq, bw, sshpass, fzf and python3 installed
- make python venv
python3 -m venv venv - activate venv
. ./venv/bin/activate - install requirements
pip install -r requirements.txt - run
nbcli init - edit pynetbox 'url' and 'token' entries in user_config.yml: ~/.nbcli/user_config.yml
- unlock BW vault
bw unlockand export BW_SESSION key shell variable - make sure that you have "nbcli" and "sshdevicepass" in PATH (I have made softlinks to ~/.local/bin)
- run
sshdevicepass
- Add nbcli results caching (call to nbcli takes a long time)