Hi. Do you have proof that it isn't properly running as root? That option > should ensure the provisioner runs as root. Do you have a debug > log showing the run of `vagrant up` with the provisioner running?
The problem in fact has nothing to do with running as root. Everything in this script should run as the vagrant user fine, and does if I run it directly in the vm. The problem is when running it via the vagrant provisioner. Also your script is expecting an argument, but in Vagrant you aren't > providing anything at all to the script, which result > in your variable being unset. This doesn't make much sense. Which part of the bash code are you referring to? If there were an unset variable, using set -euo pipefail (i.e. so called strict mode) would fail the script fast. Here is a summary of each option from bash's manual: -e Exit immediately if a pipeline (see Pipelines <https://www.gnu.org/software/bash/manual/html_node/Pipelines.html#Pipelines>), which may consist of a single simple command (see Simple Commands <https://www.gnu.org/software/bash/manual/html_node/Simple-Commands.html#Simple-Commands>), a list (see Lists <https://www.gnu.org/software/bash/manual/html_node/Lists.html#Lists>), or a compound command (see Compound Commands <https://www.gnu.org/software/bash/manual/html_node/Compound-Commands.html#Compound-Commands>) returns a non-zero status. -u Treat unset variables and parameters other than the special parameters ‘@’ or ‘*’ as an error when performing parameter expansion. -o pipefail If set, the return value of a pipeline is the value of the last (rightmost) command to exit with a non-zero status, or zero if all commands in the pipeline exit successfully. On Monday, March 4, 2019 at 10:05:25 AM UTC-8, Brian Cain wrote: > > > > On Mon, Mar 4, 2019 at 9:52 AM shaun smiley <[email protected] > <javascript:>> wrote: > >> That shouldn't matter, but I tried it any way: >> >> config.vm.provision "shell", inline: $test_apt, privileged: true >> >> and I see the same disparity. The commands above are in fact all running >> as the vagrant user, without any sudo or other privilege escalation. >> > > > Do you have proof that it isn't properly running as root? That option > should ensure the provisioner runs as root. Do you have a debug > log showing the run of `vagrant up` with the provisioner running? > > Also your script is expecting an argument, but in Vagrant you aren't > providing anything at all to the script, which result > in your variable being unset. > > >> >> On Monday, March 4, 2019 at 9:38:12 AM UTC-8, Brian Cain wrote: >>> >>> By default, the shell provisioner does not run as root. This could >>> explain the reason why you get >>> different results. Your example outside of vagrant was run as root, >>> where as the provisioner in >>> Vagrant was run as the Vagrant user: >>> >>> https://www.vagrantup.com/docs/provisioning/shell.html#privileged >>> >>> You can update the provisioner to run as root with this option, which >>> might fix it. >>> >>> On Sun, Mar 3, 2019 at 4:44 PM shaun smiley <[email protected]> wrote: >>> >>>> I added >>>> >>>> set -euo pipefail >>>> >>>> to the top of the embedded bash script, which would fail instantly on >>>> errors. I still get different results, but no errors. >>>> >>>> On Saturday, March 2, 2019 at 5:13:16 PM UTC-8, shaun smiley wrote: >>>>> >>>>> I have a strange issue where the bash code I put into Vagrantfile and >>>>> run with 'provision' gives different output than if I copy/paste the >>>>> exact >>>>> same code into the shell of the vagrant machine. >>>>> >>>>> Here's a stripped down version of my Vagrantfile I've gotten to prove >>>>> this strange issue. >>>>> >>>>> # -*- mode: ruby -*- >>>>> # vi: set ft=ruby : >>>>> >>>>> $test_apt = <<-SCRIPT >>>>> #!/usr/bin/env bash >>>>> >>>>> dpkg_find() { >>>>> pkgname="$1" >>>>> echo "in dpkg_find, pkgname=${pkgname}" >>>>> dpkg --get-selections | egrep "${pkgname}"'\s+install' && { >>>>> echo "FOUND" >>>>> } || { >>>>> echo "NOT_FOUND" >>>>> } >>>>> } >>>>> >>>>> dpkg_find vim >>>>> SCRIPT >>>>> >>>>> Vagrant.configure("2") do |config| >>>>> config.vm.box = "peru/ubuntu-18.04-desktop-amd64" >>>>> config.vm.box_version = "20190222.03" >>>>> config.vm.network :private_network, ip: '192.168.85.102' >>>>> config.vm.provision "shell", inline: $test_apt >>>>> end >>>>> >>>>> >>>>> $ vagrant provision >>>>> ==> default: Running provisioner: shell... >>>>> default: Running: inline script >>>>> default: in dpkg_find, pkgname=vim >>>>> default: NOT_FOUND >>>>> >>>>> >>>>> >>>>> >>>>> >>>>> I can copy paste the dpkg_find function and its call line and get >>>>> different output! >>>>> >>>>> $ vagrant ssh >>>>> >>>>> vagrant@linux:~$ sudo su - >>>>> root@linux:~# dpkg_find() { >>>>> pkgname="$1" >>>>> echo "in dpkg_find, pkgname=${pkgname}" >>>>> dpkg --get-selections | egrep "${pkgname}"'\s+install' && { >>>>> echo "FOUND" >>>>> } || { >>>>> echo "NOT_FOUND" >>>>> } >>>>> } >>>>> >>>>> >>>>> >>>>> root@linux:~# dpkg_find vim >>>>> in dpkg_find, pkgname=vim >>>>> vim install >>>>> FOUND >>>>> >>>>> >>>>> >>>>> What is going on here? >>>>> >>>>> -- >>>> This mailing list is governed under the HashiCorp Community Guidelines >>>> - https://www.hashicorp.com/community-guidelines.html. Behavior in >>>> violation of those guidelines may result in your removal from this mailing >>>> list. >>>> >>>> GitHub Issues: https://github.com/mitchellh/vagrant/issues >>>> IRC: #vagrant on Freenode >>>> --- >>>> You received this message because you are subscribed to the Google >>>> Groups "Vagrant" group. >>>> To unsubscribe from this group and stop receiving emails from it, send >>>> an email to [email protected]. >>>> To view this discussion on the web visit >>>> https://groups.google.com/d/msgid/vagrant-up/6607f137-4311-4a8c-892d-7dae7bfaa274%40googlegroups.com >>>> >>>> <https://groups.google.com/d/msgid/vagrant-up/6607f137-4311-4a8c-892d-7dae7bfaa274%40googlegroups.com?utm_medium=email&utm_source=footer> >>>> . >>>> For more options, visit https://groups.google.com/d/optout. >>>> >>> >>> >>> -- >>> Brian Cain >>> >> -- >> This mailing list is governed under the HashiCorp Community Guidelines - >> https://www.hashicorp.com/community-guidelines.html. Behavior in >> violation of those guidelines may result in your removal from this mailing >> list. >> >> GitHub Issues: https://github.com/mitchellh/vagrant/issues >> IRC: #vagrant on Freenode >> --- >> You received this message because you are subscribed to the Google Groups >> "Vagrant" group. >> To unsubscribe from this group and stop receiving emails from it, send an >> email to [email protected] <javascript:>. >> To view this discussion on the web visit >> https://groups.google.com/d/msgid/vagrant-up/96052a87-df0c-43db-9885-0140c30cd006%40googlegroups.com >> >> <https://groups.google.com/d/msgid/vagrant-up/96052a87-df0c-43db-9885-0140c30cd006%40googlegroups.com?utm_medium=email&utm_source=footer> >> . >> For more options, visit https://groups.google.com/d/optout. >> > > > -- > Brian Cain > -- This mailing list is governed under the HashiCorp Community Guidelines - https://www.hashicorp.com/community-guidelines.html. Behavior in violation of those guidelines may result in your removal from this mailing list. GitHub Issues: https://github.com/mitchellh/vagrant/issues IRC: #vagrant on Freenode --- You received this message because you are subscribed to the Google Groups "Vagrant" group. To unsubscribe from this group and stop receiving emails from it, send an email to [email protected]. To view this discussion on the web visit https://groups.google.com/d/msgid/vagrant-up/6774d456-10f9-4aa6-96cb-28f47123156f%40googlegroups.com. For more options, visit https://groups.google.com/d/optout.
