Skip to content

Instantly share code, notes, and snippets.

@michaelcontento
Last active August 29, 2015 14:00
Show Gist options
  • Save michaelcontento/11355729 to your computer and use it in GitHub Desktop.
Save michaelcontento/11355729 to your computer and use it in GitHub Desktop.
#!/usr/bin/env bash
HOSTNAME="vagrant"
HOSTSFILE="./hosts"
CONFIG=$(vagrant ssh-config)
HOST=$(echo "$CONFIG" | egrep -o "HostName .+" | cut -d" " -f2-)
PORT=$(echo "$CONFIG" | egrep -o "Port .+" | cut -d" " -f2-)
USER=$(echo "$CONFIG" | egrep -o "User .+" | cut -d" " -f2-)
KEY=$(echo "$CONFIG" | egrep -o "IdentityFile .+" | cut -d" " -f2-)
LINE="$HOSTNAME \
ansible_ssh_host=$HOST \
ansible_ssh_port=$PORT \
ansible_ssh_user=$USER \
ansible_ssh_private_key_file=$KEY"
sed -i "" -e "s#^$HOSTNAME .*#$LINE#g" $HOSTSFILE
ANSIBLE_HOST_KEY_CHECKING=False ansible $@
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment