From 4587eca602aa0e9ca7c764afcbd1b7f7ceefcfbc Mon Sep 17 00:00:00 2001 From: Ben Word Date: Thu, 13 Dec 2018 14:17:51 -0700 Subject: [PATCH] Add Vagrant `ssh-config` to `~/.ssh/config` on `vagrant up` --- CHANGELOG.md | 1 + Vagrantfile | 15 +++++++++++---- bin/ssh-vagrant-config.sh | 8 ++++++++ bin/xdebug-tunnel.sh | 3 +-- 4 files changed, 21 insertions(+), 6 deletions(-) create mode 100755 bin/ssh-vagrant-config.sh diff --git a/CHANGELOG.md b/CHANGELOG.md index 6c3fa6e880..af490d2498 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,4 +1,5 @@ ### HEAD +* Add Vagrant `ssh-config` to `~/.ssh/config` on `vagrant up` ([#1042](https://github.com/roots/trellis/pull/1042)) * [BREAKING] Add Ubuntu 18.04 support and default to it ([#992](https://github.com/roots/trellis/pull/992)) * Python 3 support ([#1031](https://github.com/roots/trellis/pull/1031)) * Allow customizing Nginx `worker_connections` ([#1021](https://github.com/roots/trellis/pull/1021)) diff --git a/Vagrantfile b/Vagrantfile index e06ac3f5f7..b4e57ca282 100644 --- a/Vagrantfile +++ b/Vagrantfile @@ -1,6 +1,3 @@ -# -*- mode: ruby -*- -# vi: set ft=ruby : - ANSIBLE_PATH = __dir__ # absolute path to Ansible directory on host machine ANSIBLE_PATH_ON_VM = '/home/vagrant/trellis'.freeze # absolute path to Ansible directory on virtual machine @@ -135,9 +132,19 @@ Vagrant.configure('2') do |config| extra_vars = Hash[vars.split(',').map { |pair| pair.split('=') }] ansible.extra_vars.merge!(extra_vars) end + + if !Vagrant::Util::Platform.windows? + config.trigger.after :up do |trigger| + # Add Vagrant ssh-config to ~/.ssh/config + trigger.run = { + path: File.join(provisioning_path, 'bin/ssh-vagrant-config.sh'), + args: [main_hostname] + } + end + end end - # Virtualbox settings + # VirtualBox settings config.vm.provider 'virtualbox' do |vb| vb.name = config.vm.hostname vb.customize ['modifyvm', :id, '--cpus', vconfig.fetch('vagrant_cpus')] diff --git a/bin/ssh-vagrant-config.sh b/bin/ssh-vagrant-config.sh new file mode 100755 index 0000000000..77ea4ddd50 --- /dev/null +++ b/bin/ssh-vagrant-config.sh @@ -0,0 +1,8 @@ +#!/bin/bash +vagrant_host=$1 + +# Add Vagrant ssh-config to ~/.ssh/config +sed "/^$/d;s/Host /$NL&/" ~/.ssh/config | sed '/^Host '"$vagrant_host"'$/,/^$/d;' > config && +cat config > ~/.ssh/config && +rm config && +vagrant ssh-config --host ${vagrant_host} >> ~/.ssh/config diff --git a/bin/xdebug-tunnel.sh b/bin/xdebug-tunnel.sh index 112e7effe2..e60e4d48bb 100755 --- a/bin/xdebug-tunnel.sh +++ b/bin/xdebug-tunnel.sh @@ -1,5 +1,4 @@ -#!/usr/bin/env bash - +#!/bin/bash show_usage() { echo " Usage: bin/xdebug-tunnel.sh