So I know you can use the following to run as a different user:
config.ssh.username = "ubuntu"
config.ssh.private_key_path = File.expand_path("../ssh_key", __FILE__)
I'm provisioning the default ubuntu/trusty64 on Virtualbox and if i use the --provider=aws flag, it will spin up an EC2 instance. I'm also using Ansible to configure the VM/instance.
The problem I'm running into is using the 'ubuntu' user to be configured. I was hoping that there is a way to run a shell script prior to vagrant ssh'ing into the Virtualbox. I tried running this as a shell script:
sudo cp -f /vagrant/ssh_key /home/ubuntu/.ssh/authorized_keys
sudo sed -i '/PasswordAuthentication yes/c\PasswordAuthentication no' /etc/ssh/sshd_config
sudo service ssh restart
But I believe vagrant will try to ssh first and then run the shell script. Is there any way around this or do I have to build my own vagrant box and have this setting in place?
The reason I need to do this is because I'm referencing files in my Ansible playbook and it doesn't always interpret ~/ with the correct directory. I could write out the whole path, vagrant's home path is /home/vagrant/ and the EC2 instance is /home/ubuntu/ and that would look messy. I'm not 100% sure how I can have conditionals in place (as in Ansible knowing I'm running this on Virtualbox or AWS).