There is a problem with the path to a shell script on windows.
On linux, the Vagrantfile works fine.
# -*- mode: ruby -*-
# vi: set ft=ruby :
VAGRANTFILE_API_VERSION = "2"
Vagrant.configure(VAGRANTFILE_API_VERSION) do |config|
config.vm.box = "ubuntu/trusty64"
config.vm.provider :virtualbox do |vb|
vb.name = "studstat_dev"
end
config.vm.network "forwarded_port", guest: 8000, host: 8888
config.vm.network "forwarded_port", guest: 5432, host: 15432
# Provisioning mit Shell-Script
config.vm.provision "shell", path: "studstat.sh"
end
studstat.sh
#!/bin/sh -e
# Edit the following to change the name of the database user that will be created:
APP_DB_USER=vagrant
APP_DB_PASS=vagrant
# Edit the following to change the name of the database that is created (defaults to the user name)
APP_DB_NAME=studstat
# Edit the following to change the version of PostgreSQL that is installed
PG_VERSION=9.4
export DEBIAN_FRONTEND=noninteractive
PG_REPO_APT_SOURCE=/etc/apt/sources.list.d/pgdg.list
if [ ! -f "$PG_REPO_APT_SOURCE" ]
then
# Add PG apt repo:
echo "deb http://apt.postgresql.org/pub/repos/apt/ trusty-pgdg main" > "$PG_REPO_APT_SOURCE"
# Add PGDG repo key:
wget --quiet -O - http://apt.postgresql.org/pub/repos/apt/ACCC4CF8.asc | apt-key add -
fi
# Update package list and upgrade all packagesini
apt-get update
apt-get -y upgrade
# install packages for postgres + python3
apt-get -y install "postgresql-$PG_VERSION" "postgresql-contrib-$PG_VERSION"
apt-get -y install vim git python3-setuptools python3-dev libpq-dev python3-pip
# install virtualenv via pip3, not yet in ubuntu repository (20.11.15)
pip3 install virtualenv
PG_CONF="/etc/postgresql/$PG_VERSION/main/postgresql.conf"
PG_HBA="/etc/postgresql/$PG_VERSION/main/pg_hba.conf"
PG_DIR="/var/lib/postgresql/$PG_VERSION/main"
# Edit postgresql.conf to change listen address to '*':
sed -i "s/#listen_addresses = 'localhost'/listen_addresses = '*'/" "$PG_CONF"
# Append to pg_hba.conf to add password auth:
echo "host all all all md5" >> "$PG_HBA"
# Explicitly set default client_encoding
echo "client_encoding = utf8" >> "$PG_CONF"
# generate locales
locale-gen de_DE.UTF-8
update-locale LANG=de_DE.UTF-8
# Restart so that all new config is loaded:
service postgresql restart
cat << EOF | su - postgres -c psql
-- Create the database user:
CREATE USER $APP_DB_USER WITH PASSWORD '$APP_DB_PASS';
-- Create the database:
CREATE DATABASE $APP_DB_NAME WITH OWNER=$APP_DB_USER
LC_COLLATE='de_DE.UTF-8'
LC_CTYPE='de_DE.UTF-8'
ENCODING='UTF8'
TEMPLATE=template0;
EOF
The script is in the same folder as the Vagrantfile. Relevant output of vagrant shell:
==> default: Running provisioner: shell...
default: Running: C:Users/hema0004/AppData/Local/Temp/vagrant-shell20160201-2732-1v2m7qa.sh
==> default: gpg: no valid OpenPGP data found.
The SSH command responded with a non-zero exit status. Vagrant assumes, that this means the command failed. The output for this command should be in the log above. Please read the output to determine what went wrong.
The given path to log does not exist on my mashine.
Without shell script, vagrant works fine, any ideas?
[Edit]: I can access the machine but I can not execute the script from within the machine:
/bin/sh: 0: Illegal option -
Thx, martin
The problem was that the box had no access to the internet because of missing environment variables. These variables should have been provided via the vagrant-proxyconf plugin. The underlaying problem was, that path to $VAGRANT_HOME where the proxy configuration is provided was wrong.
can you try from the following repo
# Add PGDG repo key:
apt-get install -y ca-certificates wget
wget --quiet -O - https://www.postgresql.org/media/keys/ACCC4CF8.asc | apt-key add -
Related
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
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.
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
I am trying to create a consul cluster using vagrant and virtual box.
While trying to download consul, wget is unable to establish SSL connection.
Below are the logs from vagrant. wget is working fine for other downloads and I verified that the consul download link is working too. Curl works fine on this link too. But, weirdly if I use CURl in vagrant provision, it simply is not downloading (no logs) at all.
Can some one help me with this weird wget issue? I tried upgrading 'wget' too.
==> consulredis1: --2017-01-11 02:17:04-- https://releases.hashicorp.com/consul/0.6.4/consul_0.6.4_linux_amd64.zip
==> consulredis1: Resolving releases.hashicorp.com (releases.hashicorp.com)...
==> consulredis1: 151.101.65.183
==> consulredis1: ,
==> consulredis1: 151.101.129.183
==> consulredis1: ,
==> consulredis1: 151.101.193.183
==> consulredis1: , ...
==> consulredis1: Connecting to releases.hashicorp.com (releases.hashicorp.com)|151.101.65.183|:443...
==> consulredis1: connected.
==> consulredis1: Unable to establish SSL connection.
Here is my provisioning script
#!/bin/bash
# Step 1 - Get the necessary utilities and install them.
sudo apt-get update
sudo apt-get install -y unzip curl wget
sudo apt-get install -y make gcc build-essential
#apt-get install
# Step 2 - Copy the init script to the /etc/init folder.
cp /vagrant/consul.conf /etc/init/consul.conf
# Step 3 - Get the Consul Zip file and extract it.
cd /usr/local/bin
wget http://download.redis.io/redis-stable.tar.gz
curl -k http://releases.hashicorp.com/consul/0.6.4/consul_0.6.4_linux_amd64.zip
unzip *.zip
rm *.zip
# Step 4 - Make the Consul directory.
sudo mkdir -p /etc/consul.d
sudo chmod a+w /etc/consul.d
sudo mkdir /var/consul
# Step 5 - Copy the server configuration.
cp $1 /etc/consul.d/config.json
# Step 6 - Start Consul
exec consul agent -config-file=/etc/consul.d/config.json
My Vagrantfile contents
VAGRANTFILE_API_VERSION = "2"
Vagrant.configure(VAGRANTFILE_API_VERSION) do |config|
config.vm.box = "hashicorp/precise64"
config.vm.define "consulredis1" do |consulredis1|
config.vm.provision "shell" do |s|
s.path = "provision.sh"
s.args = ["/vagrant/node1/config.json","/vagrant/node1/redis-cluster-1.init.conf","/vagrant/node1/redis-cluster-1.conf"]
end
consulredis1.vm.hostname = "consulredis1"
consulredis1.vm.network "private_network", ip: "172.20.20.10"
end
end
It appears that Hashicorp, the maintainer of Consul, recently changed its download servers to require TLS v1.2 exclusively:
Fastly (who are fronting the releases.hashicorp.com) confirmed that this issue is caused by a change to the Hashicorp endpoint who recently went to support TLS v 1.2 only and removed support for earlier versions (1.0 and 1.1). Unfortunately, the current cURL and related libraries (e.g. OpenSSL) versions on our Precise containers don't support TLS v 1.2.
(notes here, including someone from the Hashicorp weighing in)
It appears that the simplest fix, as noted elsewhere in this question, is to upgrade the version of Ubuntu. If you're not able to, you may be able to force wget to choose a specific TLS version (1.2):
wget https://releases.hashicorp.com/consul/0.6.4/consul_0.6.4_linux_amd64.zip --secure-protocol=TLSv1_2
You need to upgrade some libraries (including libssl) so the best is to include a apt-get dist-upgrade -y)
#!/bin/bash
# Step 1 - Get the necessary utilities and install them.
sudo apt-get update
sudo apt-get install -y unzip curl wget
sudo apt-get install -y make gcc build-essential
sudo apt-get dist-upgrade -y
#apt-get install
# Step 2 - Copy the init script to the /etc/init folder.
cp /vagrant/consul.conf /etc/init/consul.conf
# Step 3 - Get the Consul Zip file and extract it.
cd /usr/local/bin
wget http://download.redis.io/redis-stable.tar.gz -nc -nv
wget http://releases.hashicorp.com/consul/0.6.4/consul_0.6.4_linux_amd64.zip -nc -nv
unzip *.zip
rm *.zip
# Step 4 - Make the Consul directory.
sudo mkdir -p /etc/consul.d
sudo chmod a+w /etc/consul.d
sudo mkdir /var/consul
# Step 5 - Copy the server configuration.
cp $1 /etc/consul.d/config.json
# Step 6 - Start Consul
exec consul agent -config-file=/etc/consul.d/config.json
There seems to be issue with the distribution from "hashicorp/precise64".
I simply switched to using "ubuntu/trusty64" and wget worked fine.
#config.vm.box = "hashicorp/precise64"
config.vm.box = "ubuntu/trusty64"
I have a vagrant provisioning script which succeeds -- I can see the output from the logs and my dependencies are being installed, my directories and files are being created and copied over, etc. but when I vagrant ssh into the VM none of the folders, files, env variables, and installations are there.
Edit: git, curl, etc. work, but gvm, go, and $GOPATH etc do not, and my go directory does not exist
I'm confident the provisioning works correctly because I can run my web server from the script and confirm the application is being served.
Is this just the way Vagrant is set up? What's the point of vagrant ssh if so?
I'm running the default "hashicorp/precise32" box, Ubuntu 12.04, default provider.
Shell script
#! /bin/bash
echo "Provisioning virtual machine"
sudo apt-get update
echo "Installing Dependencies"
# Base dependencies: curl git
# Dependencies for gvm: make bison
sudo apt-get install curl git make bison -y 2> /dev/null
# Dependencies for add-apt-repository: python-software-properties software-properties-common
sudo apt-get install python-software-properties software-properties-common -y 2> /dev/null
# This allows us to get an updated version of git, which we need for gvm
sudo add-apt-repository ppa:git-core/ppa -y 2> /dev/null
sudo apt-get update
sudo apt-get install git -y 2> /dev/null
echo "Installing GVM"
bash < <(curl -s -S -L https://raw.githubusercontent.com/moovweb/gvm/master/binscripts/gvm-installer)
source ~/.gvm/scripts/gvm
echo "Installing and configuring Go"
gvm install go1.4
gvm use go1.4 --default
mkdir -p ~/go/{bin,pkg,src}
export GOPATH=$HOME/go
export PATH=$PATH:$GOPATH/bin
echo "Installing Nginx"
sudo apt-get install nginx -y 2> /dev/null
Vagrantfile
`# -*- mode: ruby -*-
# vi: set ft=ruby :
Vagrant.configure(2) do |config|
config.vm.box = "hashicorp/precise32"
config.vm.provision :shell, path: "init.sh"
config.vm.network :forwarded_port, host: 4000, guest: 8080
end`
The Vagrant provisioning script is running as root, so ~ refers to /root instead of /home/vagrant.
Options to resolve are su -c "*your command*" vagrant or using absolute paths, which is probably the best approach.
Similar issue: Why is my Vagrant bootstrap file not modifying bash_login?
And more detail in my answer here: Vagrant - Rails Not Installed