On Mon, Mar 4, 2019 at 9:52 AM shaun smiley <[email protected]> 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].
> 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/CADHESCUo-eaSAwBM%2BD61NuQXuikYP3mBTJbZcV%2Btcm-CRbZVNQ%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to