Recently I wanted to build a virtual machine with Debian 8, PostgreSQL and Python, to import some data. I use Windows as my main operating system, plus VirtualBox for virtualization, and my best option to create the virtual machine recipe (vagrantfile) was Vagrant, because AZK didn’t support Windows (at the moment of writing, still doesn’t). With the recipe, I could deliver to my client a virtual machine ready for development and production environments.
I went through some problems, which were specific to the Vagrant 1.8.1 and Windows (7 and 10) mix, and I would like to share the solutions that I found to solve everything.
The first problem was the “‘rsync’ could not be found on your path. Make sure that rsync is properly installed on your system and available on the PATH” error.
The solution was to install Cygwin, checking the openssh and rsync options. I also had to insert a new environment variable called HOME, with %USERPROFILE% as value.
Finally, I’ve edited the C:\cygwin64\etc\nsswitch.conf file, inserting the line below:
1 |
db_home: /%H |
The second problem was the “rsync error: error in rsync protocol data stream (code 12) at io.c(226) [sender=3.1.1]” error, as the image below shows:
The solution was to edit the C:\HashiCorp\Vagrant\embedded\gems\gems\vagrant-1.8.1\plugins\synced_folders\rsync\helper.rb file, commenting the lines of the snippet below:
1 2 3 4 5 6 7 8 9 10 11 |
rsh = [ "ssh -p #{ssh_info[:port]} " + proxy_command + #"-o ControlMaster=auto " + #"-o ControlPath=#{controlpath} " + #"-o ControlPersist=10m " + "-o StrictHostKeyChecking=no " + "-o IdentitiesOnly=true " + "-o UserKnownHostsFile=/dev/null", ssh_info[:private_key_path].map { |p| "-i '#{p}'" }, ].flatten.join(" ") |
The third error was the “==> default: stdin: is not a tty“, and the solution was to add the snippet below on the vagrantfile:
1 2 3 4 |
config.vm.provision "fix-no-tty", type: "shell" do |s| s.privileged = false s.inline = "sudo sed -i '/tty/!s/mesg n/tty -s \\&\\& mesg n/' /root/.profile" end |
With all this, my recipe worked normally on Vagrant and the virtual machine was created with everything I wanted. Here is the final recipe:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 |
Vagrant.configure(2) do |config| config.vm.box = "debian/jessie64" config.vm.box_check_update = false config.vm.hostname = "superbuybi" config.vm.network "private_network", ip: "192.168.1.2" config.vm.provider "virtualbox" do |vb| vb.name = "superbuybi" vb.gui = false vb.memory = "1024" end config.vm.provision "fix-no-tty", type: "shell" do |s| s.privileged = false s.inline = "sudo sed -i '/tty/!s/mesg n/tty -s \\&\\& mesg n/' /root/.profile" end config.vm.provision "file", source: "pgdg.list", destination: "/tmp/pgdg.list" config.vm.provision "file", source: "get-pip.py", destination: "/tmp/get-pip.py" config.vm.provision "file", source: "create_db.sql", destination: "/tmp/create_db.sql" config.vm.provision "shell", inline: <<-SHELL sudo mv /tmp/pgdg.list /etc/apt/sources.list.d/pgdg.list wget --quiet -O - https://www.postgresql.org/media/keys/ACCC4CF8.asc | sudo apt-key add - sudo apt-get update -y && sudo apt-get upgrade -y sudo apt-get install build-essential python-dev vim locate ack-grep htop zip postgresql-9.5 postgresql-client-9.5 postgresql-server-dev-9.5 libpq-dev -y sudo -u postgres psql < /tmp/create_db.sql cd /tmp sudo python get-pip.py sudo pip install SQLAlchemy psycopg2 SHELL end |