Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

pkg_add can't find things when run from config.vm.provision #30

Open
mcandre opened this issue Oct 20, 2017 · 3 comments
Open

pkg_add can't find things when run from config.vm.provision #30

mcandre opened this issue Oct 20, 2017 · 3 comments

Comments

@mcandre
Copy link

mcandre commented Oct 20, 2017

sudo pkg_add works in a manual vagrant ssh session, but when I try to automate installing the same packages by specifying a config.vm.provision in the Vagrantfile, for some reason pkg_add fails.

Perhaps there is some shell configuration that is not being fully loaded in non-interactive mode?

@mcandre
Copy link
Author

mcandre commented Oct 20, 2017

Ah, PKG_PATH is being configured by /home/vagrant/.profile, which appears to not be loaded by non-interactive sessions, which includes config.vm.provision.

As a workaround, I am explicitly setting PKG_PATH when I run pkg_add commands:

Vagrantfile:

Vagrant.configure("2") do |config|
  config.vm.box = "ryanmaclean/openbsd-6.0"
  config.vm.provision "shell", path: "bootstrap.sh"
end

bootstrap.sh:

#!/bin/sh
sudo PKG_PATH=http://ftp.openbsd.org/pub/OpenBSD/6.0/packages/amd64/ pkg_add rust cargo

But it would be nice if PKG_PATH were available by default for all sessions, including non-interactive sessions.

@dentarg
Copy link
Collaborator

dentarg commented Oct 21, 2017

Perhaps there is some shell configuration that is not being fully loaded in non-interactive mode?

Yes, from https://www.vagrantup.com/docs/provisioning/shell.html:

For POSIX-like machines, the shell provisioner executes scripts with SSH.

~/.profile isn't sourced for non-interactive / non-login login shells, for various reasons. PKG_PATH need to be set with env argument to the shell provisioner.

@dentarg
Copy link
Collaborator

dentarg commented Oct 21, 2017

Another option is to use installurl(5), not that well documented that it also works for pkg_add, but it does.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants