# -*- 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 vimSCRIPT
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
$ 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
default: dpkg: /usr/bin/dpkg /usr/lib/dpkg /etc/dpkg /usr/share/dpkg /usr/share/man/man1/dpkg.1.gz
default: egrep: /bin/egrep /usr/share/man/man1/egrep.1.gz
vagrant@linux:~$ whereis dpkg
dpkg: /usr/bin/dpkg /usr/lib/dpkg /etc/dpkg /usr/share/dpkg /usr/share/man/man1/dpkg.1.gz
vagrant@linux:~$ whereis egrep
egrep: /bin/egrep /usr/share/man/man1/egrep.1.gz
set -euo pipefail--
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 vagrant-up+...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/vagrant-up/6607f137-4311-4a8c-892d-7dae7bfaa274%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
That shouldn't matter, but I tried it any way:config.vm.provision "shell", inline: $test_apt, privileged: trueand I see the same disparity. The commands above are in fact all running as the vagrant user, without any sudo or other privilege escalation.
To view this discussion on the web visit https://groups.google.com/d/msgid/vagrant-up/96052a87-df0c-43db-9885-0140c30cd006%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
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.
-e Exit immediately if a pipeline (see Pipelines), which may consist of a single simple command (see Simple Commands), a list (see Lists), or a compound command (see 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.
FWIW
I just ran through the process of creating a VM using only your sample Vagrantfile and following the steps you describe in your email.
In all test cases the script, irrespective of context, returns NOT FOUND.
Furthermore, manual checks on the machine, as created by this example Vagrantfile, show that vim is not installed.
Unsurprisingly, apt install vim and rerunning the tests returns a consistent FOUND.
All of which suggests that you have something in your real Vagrantfile that is installing vim after the provision script does its test (and so your subsequent direct test shows vim installed. (Maybe vim is being installed as a dependency somewhere—assuming you’re not installing it directly.)
--
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 vagrant-up+...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/vagrant-up/381f75c0-dcd9-4095-b0f8-546aefa2670b%40googlegroups.com.
set -xdpkg --get-selections | egrep 'vim\\s+install'