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.)


On 3 Mar 2019, at 1:13, 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/381f75c0-dcd9-4095-b0f8-546aefa2670b%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


--
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/3DCB841F-ECDC-4F13-8AD9-B47F599B830C%40gmail.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to