Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

278
Views
¿Cómo ejecutar comandos como otro usuario durante el aprovisionamiento en Vagrant?

Vagrant ejecuta mis scripts como root durante la provisión. Pero me gustaría ejecutar, durante el tiempo de aprovisionamiento, algunos comandos como otro usuario. Así es como lo estoy haciendo en este momento:

 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"

Pero me gustaría hacer esto más agradable, algo como esto:

 #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

Es posible ? ¡Gracias!

over 4 years ago · Santiago Trujillo
2 answers
Answer question

0

al ejecutar el aprovisionamiento, es cierto que vagrant se ejecutará como root de forma predeterminada, puede cambiar este comportamiento haciendo el aprovisionamiento como

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

vagabundo luego usará el usuario definido como config.ssh.username , si no está configurado, su usuario vagabundo por defecto

Si tiene varios usuarios en su sistema y todavía quiere usar otro usuario, lo que haría sería escribir un script y ejecutarlo como su -l newuser -c "path to shell script"

over 4 years ago · Santiago Trujillo Report

0

Si desea tener la secuencia de comandos en línea con el resto, puede usar una secuencia de comandos como la siguiente.

 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 Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!