How to run ganache-cli from Vagrant box? - vagrant

I am running ganache-cli in a Vagrant box and trying to connect Metamask (Google Chrome) to it. But Metamask fails to connect to it. It connects if ganache-cli runs on the host machine. This is my Vagrant file
Vagrant file
# -*- mode: ruby -*-
# vi: set ft=ruby :
Vagrant.configure(2) do |config|
config.vm.hostname = 'ethereum'
config.vm.box = "ubuntu/bionic64"
config.vm.provision :shell, path: "setup_dev_env.sh"
config.vm.box_check_update = false
config.vm.network "forwarded_port", guest: 3000, host: 3000, host_ip: "127.0.0.1"
config.vm.network "forwarded_port", guest: 8545, host: 8545, host_ip: "127.0.0.1"
config.vm.synced_folder "SOME_PATH", "/home/vagrant/code"
config.vm.provider "virtualbox" do |vb|
vb.gui = false
vb.memory = "4096"
end
end
Contents of setup_dev_env.sh
sudo apt-get install software-properties-common
sudo add-apt-repository -y ppa:ethereum/ethereum
sudo apt-get update
sudo apt-get install -y --allow-unauthenticated python3-pip mypy build-essential ethereum npm
sudo npm install -g ganache-cli
sudo apt-get update

Start ganache-cli with ganache-cli --host 0.0.0.0 and in Metamask enter details for Custom RPC in New RPC URL as http://0.0.0.0:8545

Related

Vagrant doesn't runs Inline shell script to Install packages

All of my packages are not Installed, seems Vagrant doesn't provision Inline shell script by default.
Last time I Installed packages manually but then I ran Into permission Issues, again I tried reinstalling vagrant box but still It doesn't run the Inline script.
Vagrantfile
# -*- mode: ruby -*-
# vi: set ft=ruby :
Vagrant.configure("2") do |config|
config.vm.box = "bento/ubuntu-16.04"
config.vm.box_version = "= 2.3.5"
config.vm.synced_folder ".", "/vagrant"
config.vm.network "forwarded_port", guest: 8000, host: 8000, host_ip: "127.0.0.1"
config.vm.network "forwarded_port", guest: 8080, host: 8080, host_ip: "127.0.0.1"
config.vm.network "forwarded_port", guest: 5000, host: 5000, host_ip: "127.0.0.1"
# Work around disconnected virtual network cable.
config.vm.provider "virtualbox" do |vb|
vb.customize ["modifyvm", :id, "--cableconnected1", "on"]
end
config.vm.provision "shell", inline: <<-SHELL
apt-get -qqy update
# Work around https://github.com/chef/bento/issues/661
# apt-get -qqy upgrade
DEBIAN_FRONTEND=noninteractive apt-get -y -o Dpkg::Options::="--force- confdef" -o Dpkg::Options::="--force-confold" upgrade
apt-get -qqy install make zip unzip postgresql
apt-get -qqy install python3 python3-pip
pip3 install --upgrade pip
pip3 install flask packaging oauth2client redis passlib flask-httpauth
pip3 install sqlalchemy flask-sqlalchemy psycopg2-binary bleach requests
apt-get -qqy install python python-pip
pip2 install --upgrade pip
pip2 install flask packaging oauth2client redis passlib flask-httpauth
pip2 install sqlalchemy flask-sqlalchemy psycopg2-binary bleach requests
su postgres -c 'createuser -dRS vagrant'
su vagrant -c 'createdb'
su vagrant -c 'createdb news'
su vagrant -c 'createdb forum'
su vagrant -c 'psql forum -f /vagrant/forum/forum.sql'
vagrantTip="[35m[1mThe shared directory is located at /vagrant\\nTo access your shared files: cd /vagrant[m"
echo -e $vagrantTip > /etc/motd
wget http://download.redis.io/redis-stable.tar.gz
tar xvzf redis-stable.tar.gz
cd redis-stable
make
make install
echo "Done installing your virtual machine!"
SHELL
end
you can always run one by one the lines of your script to check which one produces an error.
Here I see you have a space on --force- confdef you can easily fix with
DEBIAN_FRONTEND=noninteractive apt-get -y -o Dpkg::Options::="--force-confdef" -o Dpkg::Options::="--force-confold" upgrade

apt-get command not found in Vagrant/Window

When I run vagran up command, I get the error apt-get command not found in vagrant, my pc is using window-10.
Vagrantfile
# -*- mode: ruby -*-
# vi: set ft=ruby :
Vagrant.configure("2") do |config|
# VM Box
config.vm.box = "centos-7"
config.vm.network "private_network", ip: "192.168.33.100"
config.vm.provider "virtualbox" do |vb|
vb.memory = 2048
vb.cpus = 4
end
config.vm.provision "shell", path: "bootstrap.sh"
end
bootstrap.sh
sudo apt-get update
sudo apt-get apgrate
sudo apt-get install -y git
you're using a centos box
config.vm.box = "centos-7"
so you should use the yum package manager, apt is used for ubuntu family and is not compatible with the other os family (Debian vs Fedora)
To install git on centos replace your bootstrap script by
yum update
yum install -y git
Have you tried using yum and trying $ vagrant box update? Also, you can get more in depth logs by using $ vagrant up --debug or if you would like to save it to a file $ vagrant up --debug &> vagrant.log. I always recommend doing some VM house keeping as well by making sure all VMs are stopped then run $ vagrant reload --provision on the VM having the issues. As always, the best part of using Vagrant is the ability to wipe it and start over again.

How do I add PHPadmin to my bootstrap.sh commands?

I've been away from PHP nearly four years, I've been working in javascript and Node.JS instead. I have a memory of what tools I was comfortable working with.. it's a rusty memory how it all went together. I've followed Traversy's tutorial to get the LAMP box running
and have connected from MySQL WorkBench.
I'd like to use PHPAdmin, How do I add PHPadmin to my bootstrap.sh commands?
Installing phpMyAdmin On Vagrant
I like this version best, cause each domain has it's own /phpadmin, but I don't understand how he is editing the config file from inside bootstrap.sh
A super-simple Vagrant LAMP stack bootstrap (installable with one command)
I tried this one first, but got an error from the first curly brace, saying it didn't recognize the character..
bootstrap.sh
# Use single quotes instead of double quotes to make it work with special-character passwords
PASSWORD='12345678'
PROJECTFOLDER='myproject'
# Update Packages
apt-get update
# Upgrade Packages
apt-get upgrade
# Basic Linux Stuff
apt-get install -y git
# Apache
apt-get install -y apache2
# Enable Apache Mods
a2enmod rewrite
#Add Onrej PPA Repo
apt-add-repository ppa:ondrej/php
apt-get update
# Install PHP
apt-get install -y php7.2
# PHP Apache Mod
apt-get install -y libapache2-mod-php7.2
# Restart Apache
service apache2 restart
# PHP Mods
apt-get install -y php7.2-common
apt-get install -y php7.2-mcrypt
apt-get install -y php7.2-zip
# Set MySQL Pass
debconf-set-selections <<< 'mysql-server mysql-server/root_password password $PASSWORD'
debconf-set-selections <<< 'mysql-server mysql-server/root_password_again password $PASSWORD'
# Install MySQL
apt-get install -y mysql-server
# PHP-MYSQL lib
apt-get install -y php7.2-mysql
# Install phpmyadmin
# apt-get install phpmyadmin
# Restart Apache
sudo service apache2 restart
Vagrantfile
# -*- mode: ruby -*-
# vi: set ft=ruby :
Vagrant.configure("2") do |config|
# Box Settings
config.vm.box = "ubuntu/trusty64"
# Provider Settings
config.vm.provider "virtualbox" do |vb|
vb.memory = 2048
vb.cpus = 4
end
# Network Settings
# config.vm.network "forwarded_port", guest: 80, host: 8080
# config.vm.network "forwarded_port", guest: 80, host: 8080, host_ip: "127.0.0.1"
config.vm.network "private_network", ip: "192.168.33.10"
# config.vm.network "public_network"
# Folder Settings
config.vm.synced_folder ".", "/var/www/html", :nfs => { :mount_options => ["dmode=777", "fmode=666"] }
# Provision Settings
# config.vm.provision "shell", inline: <<-SHELL
# apt-get update
# apt-get install -y apache2
# SHELL
config.vm.provision "shell", path: "bootstrap.sh"
end

Vagrant puppet provision failure. Error msg: "The `puppet` binary appears not to be in the PATH of the guest. ... "

Vagrant puppet provision failure with ubuntu/xenial64.
Error message:
This could be because the PATH is not properly setup or perhaps Puppet
is not installed on this guest. Puppet provisioning can not continue
without Puppet properly installed.
Vagrantfile:
Note: The below setup worked fine with ubuntu/trusty64
# -*- mode: ruby -*-
# vi: set ft=ruby :
Vagrant.configure(2) do |config|
config.vm.box = "ubuntu/xenial64"
config.vm.hostname = "elasticsearch-learn"
config.vm.box_url = "init"
config.vm.network "forwarded_port", guest: 9200, host: 9200
config.vm.network "forwarded_port", guest: 5601, host: 5601
config.vm.provider "virtualbox" do |vb|
vb.memory = "1024"
end
config.vm.provision :puppet do |puppet|
puppet.manifests_path = "puppet/manifests"
puppet.module_path = "puppet/modules"
end
end
Vagrant running directory structure:
vagrant_devenv (master)*$ tree -L 2
.
├── README.rst
├── Vagrantfile
├── installpuppet.sh
├── puppet
│   ├── manifests
│   └── modules
├── requirements.txt
└── ubuntu-xenial-16.04-cloudimg-console.log
Optional:
Just for reference, if needed. I use my old git repo and make local changes for each project. Its not updated for xenial64 but the puppet packages are same. But you can find the puppet manifests and modules I generally use there
The issue is due to puppet was not found in ubuntu/xenial64. So included a step in installing puppet-agent before puppet provisioning.
I changed the Vagrantfile with an additional step to install puppet-agent before the puppet provision step.
config.vm.provision :"shell", path: "installpuppet.sh"
The updated Vagrantfile
# -*- mode: ruby -*-
# vi: set ft=ruby :
Vagrant.configure(2) do |config|
config.vm.box = "ubuntu/xenial64"
config.vm.hostname = "elasticsearch-learn"
config.vm.box_url = "init"
config.vm.network "forwarded_port", guest: 9200, host: 9200
config.vm.network "forwarded_port", guest: 5601, host: 5601
config.vm.provider "virtualbox" do |vb|
vb.memory = "1024"
end
config.vm.provision :"shell", path: "installpuppet.sh"
config.vm.provision :puppet do |puppet|
puppet.manifests_path = "puppet/manifests"
puppet.module_path = "puppet/modules"
end
end
installpuppet.sh contents:
apt update
apt install -y puppet
Then perform the usual 'vagrant up'
This worked for me! Hope it helps. Let me know if there are better solutions.
Or you can try this befores config.vm.provision:
web_config.vm.provision "shell", inline: "sudo apt-get update && sudo apt-get install -y puppet"
Just install puppet before run.
Full sample:
Vagrant.configure("2") do |config|
config.vm.box = "hashicorp/precise32"
config.vm.define :web do |web_config|
web_config.vm.provision "shell", inline: "sudo apt-get update && sudo apt-get install -y puppet"
web_config.vm.provision "puppet" do |puppet|
puppet.manifests_path = "puppet/manifests"
puppet.module_path = "puppet/modules"
end
end
end

unable to sync folder in vagrant

I am using vagrant box 'ubuntu/trusty64'. I am trying to sync folder in vagrant and for that, I have modified my vagrant file. The file is:
# -*- mode: ruby -*-
# vi: set ft=ruby :
Vagrant.configure("2") do |config|
config.vm.box = "foo-box"
config.vm.network "forwarded_port", guest: 8000, host: 8000, host_ip: "127.0.0.1"
config.vm.network "forwarded_port", guest: 8080, host: 8080, host_ip: "127.0.0.1"
config.vm.network "forwarded_port", guest: 5000, host: 5000, host_ip: "127.0.0.1"
# Work around disconnected virtual network cable.
config.vm.provider "virtualbox" do |vb|
vb.customize ["modifyvm", :id, "--cableconnected1", "on"]
end
Vagrant.configure("2") do |config|
config.vm.synced_folder "C:/fullstack/vagrant", "home/vagrant"
end
config.vm.provision "shell", inline: <<-SHELL
apt-get -qqy update
apt-get -qqy upgrade
apt-get -qqy install make zip unzip postgresql
apt-get -qqy install python3 python3-pip
pip3 install --upgrade pip
pip3 install flask packaging oauth2client redis passlib flask-httpauth
pip3 install sqlalchemy flask-sqlalchemy psycopg2 bleach
apt-get -qqy install python python-pip
pip2 install --upgrade pip
pip2 install flask packaging oauth2client redis passlib flask-httpauth
pip2 install sqlalchemy flask-sqlalchemy psycopg2 bleach
su postgres -c 'createuser -dRS vagrant'
su vagrant -c 'createdb'
su vagrant -c 'createdb news'
su vagrant -c 'createdb forum'
su vagrant -c 'psql forum -f /vagrant/forum/forum.sql'
vagrantTip="[35m[1mThe shared directory is located at /vagrant\\nTo access your shared files: cd /vagrant[m"
echo -e $vagrantTip > /etc/motd
wget http://download.redis.io/redis-stable.tar.gz
tar xvzf redis-stable.tar.gz
cd redis-stable
make
make install
echo "Done installing your virtual machine!"
SHELL
end
I have also tried answer given in https://stackoverflow.com/questions/29731003/synced-folder-in-vagrant-is-not-syncing-in-realtime but of no help.
The path to my project on host machine is C:\fullstack. The content of the folder fullstack is
README.md vagrant/ Vagrantfile
And further the content of vagrant folder is
catalog/ forum/ tournament/ Vagrantfile
The content in both the vagrantfile file is same.
I tried to make an empty directory in guest machine in vagrant directory but the directory didn't show in host machine. Please suggest something.
You dont need to re-introduce a configure section, just have your Vagrantfile as
Vagrant.configure("2") do |config|
config.vm.box = "foo-box"
config.vm.network "forwarded_port", guest: 8000, host: 8000, host_ip: "127.0.0.1"
config.vm.network "forwarded_port", guest: 8080, host: 8080, host_ip: "127.0.0.1"
config.vm.network "forwarded_port", guest: 5000, host: 5000, host_ip: "127.0.0.1"
# Work around disconnected virtual network cable.
config.vm.provider "virtualbox" do |vb|
vb.customize ["modifyvm", :id, "--cableconnected1", "on"]
end
config.vm.synced_folder "C:/fullstack/vagrant", "home/vagrant/stack"
Also its not really good to sync on your /home/vagrant folder directly as this folder has the .ssh folder (ssh might not work) and bash information, its better to have a subdirectory of the main home folder.

Resources