Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

273
Visualizações
How execute commands as another user during provisioning on Vagrant?

Vagrant executes my scripts as root during provision. But I would like to execute, during the provisioning time, some commands as another user. This is how I'm doing at the moment:

  su - devops -c "git clone git://github.com/sstephenson/rbenv.git .rbenv"
  su - devops -c "echo 'export PATH=\"$HOME/.rbenv/bin:$PATH\"' >> ~/.bash_profile"
  su - devops -c "echo 'eval "$(rbenv init -)"' >> ~/.bash_profile"
  su - devops -c "git clone git://github.com/sstephenson/ruby-build.git ~/.rbenv/plugins/ruby-build"
  su - devops -c "echo 'export PATH=\"$HOME/.rbenv/plugins/ruby-build/bin:$PATH\"' >> ~/.bash_profile"
  su - devops -c "source ~/.bash_profile"

But I would like to make this nicer, something like this:

#become devops user here

git clone git://github.com/sstephenson/rbenv.git .rbenv
echo 'export PATH="$HOME/.rbenv/bin:$PATH"' >> ~/.bash_profile
echo 'eval "$(rbenv init -)"' >> ~/.bash_profile

git clone git://github.com/sstephenson/ruby-build.git ~/.rbenv/plugins/ruby-build
echo 'export PATH="$HOME/.rbenv/plugins/ruby-build/bin:$PATH"' >> ~/.bash_profile
source ~/.bash_profile

# back to the root user here

Is this possible ? Thank you!

over 4 years ago · Santiago Trujillo
2 Respostas
Responde à pergunta

0

when running the provisioning, its true that vagrant will run as root by default, you can change this behavior by making the provision as

config.vm.provision "shell", privileged: false blablabla

vagrant will then use the user defined as config.ssh.username, if its not set, its vagrant user by default

If you have multiple users on your system and still want to use another user, what I would do is to write a script and execute the script as su -l newuser -c "path to shell script"

over 4 years ago · Santiago Trujillo Relatório

0

If you want to have the script inline with the rest you can use a command sequence such as the following.

sudo -u devops /bin/sh <<\DEVOPS_BLOCK
# Become devops user here
id
whoami
# Back to the root user here
DEVOPS_BLOCK
over 4 years ago · Santiago Trujillo Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda