Created
October 26, 2020 08:59
-
-
Save konstruktoid/c14c6b609e9e2c33c72ad5b169632f7f to your computer and use it in GitHub Desktop.
Generate a Ansible hosts file from running Vagrant VMs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
{ | |
for VM in $(vagrant status | grep -iE 'running.*virtualbox' | grep "$1" | awk '{print $1}'); do | |
mapfile -t VAGRANT_SSH < <(vagrant ssh-config "$VM" | awk '{print $NF}') | |
echo "[${VAGRANT_SSH[0]}]" | |
echo "${VAGRANT_SSH[1]} ansible_connection=ssh ansible_port=${VAGRANT_SSH[3]} ansible_user=${VAGRANT_SSH[2]} ansible_ssh_private_key_file=${VAGRANT_SSH[7]}" | |
done | |
} > "hosts" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment