12

Anaconda python is installed (in linux) via a bash script. I am trying to use Vagrant provisioning to get Anacaonda Python installed.

In the bash script (following the documentation bootstrap.sh example) I have a bootstrap.sh script that:

  1. wget the install script
  2. chmod +x to make it executable
  3. ./<script>.sh to install.

Installing this way fails as the installation has a few prompts, one of which requires the non-default answer.

Is it possible to automate the installation via a bash script? If not, is it necessary to use something like Puppet? I do not know Puppet at all, so have tried to avoid using...perhaps it is time to dig in?

The end goal is to ship the Vagrantfile and not host a Vagrant box.

P.S. My initial, feeble attempts made use of the linux yes command, but a better way has to exist!

Jzl5325
  • 3,898
  • 8
  • 42
  • 62

6 Answers6

20

In your bootstrap.sh just include something like:

miniconda=Miniconda3-3.7.4-Linux-x86_64.sh
cd /vagrant
if [[ ! -f $miniconda ]]; then
    wget --quiet http://repo.continuum.io/miniconda/$miniconda
fi
chmod +x $miniconda
./$miniconda -b -p /opt/anaconda

cat >> /home/vagrant/.bashrc << END
# add for anaconda install
PATH=/opt/anaconda/bin:\$PATH
END

The -b option runs in batch mode and is what you are looking for:

>>>> ./Miniconda-3.7.0-Linux-x86_64.sh -h 
usage: ./Miniconda-3.7.0-Linux-x86_64.sh [options]

Installs Miniconda 3.7.0

    -b           run install in batch mode (without manual intervention),
                 it is expected the license terms are agreed upon
    -f           no error if install prefix already exists
    -h           print this help message and exit
    -p PREFIX    install prefix, defaults to /Users/phil/miniconda

I also typically put Miniconda (or a link to it) directly in the "vagrant" where the bootstrap.sh is. That way, you are not downloading from the web during each vagrant up (after init or destroy).

Phil Cooper
  • 5,747
  • 1
  • 25
  • 41
  • Those that, like me, are not decent bash readers, can learn [about here documents](http://stackoverflow.com/a/2500451/239408) to understand what goes into .bashrc – xverges Jan 20 '17 at 20:27
  • Hey, conda has changed its repos. Can you update the script? miniconda=Miniconda3-latest-Linux-x86_64.sh wget --quiet https://repo.anaconda.com/miniconda/$miniconda – bilbohhh Jul 09 '19 at 11:08
4

I made a GitHub repository based on Phil Cooper's answer.

https://github.com/tomohiro1221/vagrant-anaconda

Tomohiro Koana
  • 782
  • 1
  • 7
  • 17
4

For people who want to start a new box with anaconda from scrach, it can be achieved by use the anaconda3 box (or other anaconda boxes) from continuumio. By using the following command to init vagrant.

vagrant init continuumio/anaconda3; vagrant up --provider virtualbox

There are other several other conda and miniconda boxes here. This approach is easy to achieve, however if you want to add conda to an existing box Phil Cooper's solution is the way to go.

Bin
  • 3,645
  • 10
  • 33
  • 57
  • While this code snippet may solve the question, [including an explanation](http://meta.stackexchange.com/questions/114762/explaining-entirely-code-based-answers) really helps to improve the quality of your post. Remember that you are answering the question for readers in the future, and those people might not know the reasons for your code suggestion. – J. Chomel Sep 21 '16 at 06:44
  • Hi J.Chomel, I added a little explanation. Thanks for your suggestion. – Bin Sep 22 '16 at 03:45
  • Silly question, when I run this and then `vagrant ssh` I get: `$ vagrant ssh [vagrant@localhost ~]$ conda --version -bash: conda: command not found` Any ideas why I can't seem to use conda ? – Greg Lever Apr 05 '19 at 10:27
2

Here is an expect script file to install Anaconda (Anaconda-2.0.1-Linux-x86_64.sh) on Vagrant:

#!/usr/bin/expect
#exp_internal 1
set timeout 600
spawn /tmp/Anaconda-2.0.1-Linux-x86_64.sh
send "\r"
send " "
send " "
send " "
send " "
send " "
expect -exact "\[no\] >>>"
send "yes\r"
expect -exact "\[/home/vagrant/anaconda\] >>>"
send "\r"
expect -exact "\[no\] >>>"
send "yes\r"

Uncomment exp_internal 1 to see the matching the timeout is for the installation time of Anaconda, took 390 seconds on my box.

Edit: I actually finished a working Vagrant environment with Anaconda here: https://github.com/colour-science/colour-vagrant

Kel Solaar
  • 3,660
  • 1
  • 23
  • 29
1

Puppet will not make this task any easier, because running interactive scripts is not part of its core features (I don't even believe it's available through 3rd party modules).

A better way does exist, through use of the expect tool. It allows you to write a robust script to interact with the input prompts of the installation process.

Felix Frank
  • 8,125
  • 1
  • 23
  • 30
1

You can use your desired image from the offical vagrant images from ContinuumIO

jagan120
  • 21
  • 4