How to run a shell script with Vagrant Digital Ocean provider?

Posted September 22, 2015 7.8k views

I’ve been running an application on Vagrant using VirtualBox as my provider and a shell script to provision the environment once the VM is running.

My shell script uses a number of commands starting with “su -vagrant -c” such as:

su - vagrant -c "rvm mount -r $1"

These all work perfectly when running the VirtualBox provider in my local environment.

However, now that I’m running this using the Vagrant Digital Ocean provider, I’m getting the following error:

==> default: No passwd entry for user 'vagrant'

Here is my Vagrantfile:

Vagrant.configure('2') do |config|

  config.vm.provider :digital_ocean do |provider, override|
    override.ssh.private_key_path = '~/.ssh/id_rsa' = 'digital_ocean'
    override.vm.box_url = ""
    override.vm.hostname = 'digitalocean-vagrant'

    provider.ssh_key_name = 'the name associated with my ssh_key on my existing account'
    provider.token = 'Here I have my token from the Digital Ocean API'
    provider.image = 'ubuntu-14-04-x64'
    provider.region = 'nyc2'
    provider.size = '512mb'

  config.vm.provision "shell" do |s|
      s.path = ""
      # argument mapping ["ruby binary url", "Ruby Version", "RVM Gemset name", "MySQL or PostgreSQL", "Rails version", "ImagineMagick required"]
      s.args = ["", "ruby-2.1.2", "Customer Name", "MySQL", "4.1.4", "true"]

Here is my file:


echo "****** Provisioning virtual machine... ******"
echo "****** Installing Ruby Dependencies ******"
cd /vagrant
sudo apt-get update
sudo apt-get install git-core curl zlib1g-dev build-essential libssl-dev libreadline-dev libyaml-dev libsqlite3-dev sqlite3 libxml2-dev libxslt1-dev libcurl4-openssl-dev python-software-properties libffi-dev -y
echo "****** Installing RVM ******"
sudo apt-get install libgdbm-dev libncurses5-dev automake libtool bison libffi-dev -y
curl -L | bash -s stable
source ~/.rvm/scripts/rvm
echo "****** Installing Ruby $1 ******"
#su - vagrant -c "rvm install $1" - this works but must compile ruby
su - vagrant -c "rvm mount -r $1" #use this if there is a binary available to avoid need to compile ruby
source /home/vagrant/.rvm/scripts/rvm
su - vagrant -c "rvm --default use $2"
su - vagrant -c "rvm gemset list"
su - vagrant -c "rvm gemset create $3"
su - vagrant -c "rvm use $2@$3 --default"
su - vagrant -c "rvm gemset list"
su - vagrant -c "ruby -v"
echo "****** Installing $4 ******"
if [ "$4" == "MySQL" ]; then
  sudo apt-get install mysql-server mysql-client libmysqlclient-dev -y
    cd /etc
    sudo sh -c 'echo "deb trusty-pgdg main" >> /etc/apt/sources.list.d/postgresql.list'    
    wget --quiet -O - | sudo apt-key add -
    sudo apt-get update
    sudo apt-get install postgresql-9.3 pgadmin3 -y
echo "****** Installing Nginx ******"
  sudo apt-get update
  sudo apt-get install nginx -y
echo "****** Installing Nodejs ******" 
  sudo apt-get update
  sudo apt-get install nodejs
  sudo apt-get install npm
echo "****** Installing Rails ******"
    su - vagrant -c "gem install rails --version=$5 --no-rdoc --no-ri"
  su - vagrant -c "rails -v"
if [ "$6" == "true" ]; then
    echo "****** Installing ImageMagick ******"
    sudo apt-get install imagemagick -y
    echo "****** ImageMagick Not Required ******"
echo "****** Completed provisioning virtual machine! ******"
# echo "****** Be sure to uncomment the passenger_root & passenger_ruby lines in /etc/nginx/nginx.conf file!!!  ******"
echo "****** Then do a 'sudo service nginx restart' ******"

I’ve tried several different options based on the issues I saw posted on the Digital Ocean Provider Github Repo


and here:

Also another post that I am unable to find now suggested including provider.setup = false

But, none of these worked.

Any other ideas what I need to do to make this work?


These answers are provided by our Community. If you find them useful, show some love by clicking the heart. If you run into issues leave a comment, or add your own answer to help others.

Submit an Answer
1 answer


It appears that the plugin doesn’t create the vargrant user. I added a sudo useradd vagrant to my script and it worked.

My script wasn’t as complex as yours, but it did run several commands as the vagrant user with su - vagrant -c "command-here" without any issue.