execute commands as user after Vagrant provisioning

Vince

There are some commands that have to be run as a normal user after the initial provisioning. I thought I could do this using a separate shell script and the command su --login -c <command> vagrant, but it's not getting the user's path or other environment settings from .bashrc.

e.g.:

#!/usr/bin/env bash
su --login -c "rbenv install 2.0.0-p353" vagrant
su --login -c "rbenv global 2.0.0-p353" vagrant
su --login -c "gem update --system" vagrant
su --login -c "yes | gem update" vagrant
su --login -c "gem install rdoc" vagrant
su --login -c "gem install rails pg" vagrant

Is there a way to do this? Maybe it has to be done with another provisioning tool like Puppet or Chef? I've thought of creating another shell script that sources the .bashrc, copying it to the box using a :file provisioner and executing the commands like that, but it seems sort of like a hack.

What's the right way to do this?

jabclab

You should be able to do this using the Vagrant Shell provisioner, e.g.

Vagrant.configure("2") do |config|
  $script = <<-SCRIPT
  rbenv install 2.0.0-p353
  rbenv global 2.0.0-p353
  gem update --system
  yes | gem update
  gem install rdoc
  gem install rails pg
  SCRIPT

  config.vm.provision "shell", inline: $script, privileged: false
end

The key is to specify privileged: false so that it will use the default user and not root.

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

How execute commands as another user during provisioning on Vagrant?

From Dev

How execute commands as another user during provisioning on Vagrant?

From Dev

programatically restart vagrant box after provisioning (Vagrant 1.4+)

From Dev

programatically restart vagrant box after provisioning (Vagrant 1.4+)

From Dev

Allow user to execute sudo commands

From Dev

Allow user to execute sudo commands

From Dev

Provisioning PostgreSQL with Puppet on Vagrant

From Dev

Vagrant provisioning and version control

From Dev

Vagrant with docker provisioning

From Dev

Render erb in Vagrant provisioning

From Dev

Running remote commands after vagrant ssh

From Dev

Run rest of batch commands after vagrant starts

From Dev

Running remote commands after vagrant ssh

From Dev

Run rest of batch commands after vagrant starts

From Dev

Execute multiple commands after [ test

From Dev

Execute multiple commands after [ test

From Dev

execute multiple commands after ssh

From Dev

Vagrant execute script or command after every guest restart (vagrant up)

From Dev

Cannot use chef provisioning in vagrant

From Dev

Vagrant Puppet Provisioning - Pear Packages

From Dev

Separate ansible provisioning playbooks in vagrant

From Dev

Vagrant Shell Provisioning runs but fails

From Dev

Vagrant multi-machine provisioning

From Dev

Vagrant Shell Provisioning runs but fails

From Dev

Having vagrant provisioning clone a repository,

From Dev

Vagrant shell provisioning phpPgAdmin password

From Dev

Upgrade php to 5.6 in Vagrant provisioning

From Dev

Provisioning Vagrant box with chef-solo and vagrant

From Java

How to execute a group of commands as another user in Bash?

Related Related

HotTag

Archive