using Vagrant getting a shell script issue and failure - macos

I have the following details:
Vagrant File:
Vagrant.configure("2") do |config|
config.vm.box = "Precise32"
config.vm.box_url = "http://files.vagrantup.com/precise32.box"
config.vm.synced_folder "./Public","/var/www/",create:true
config.vm.network :private_network, ip: "192.168.55.55"
config.vm.provision :shell, :path => "setup.sh"
end
Shell File:
sudo apt-get -y update
sudo apt-get install apache2 php5 libapache2-mod-php5
sudo sudo apachectl restart
The shell is s little limited but i want to get it to work first before i attempt all the other php stuff etc
The error i get starts here:
Do you want to continue [Y/n]? Abort.
The following SSH command responded with a non-zero exit status.
Vagrant assumes that this means the command failed!
chmod +x /tmp/vagrant-shell && /tmp/vagrant-shell
Stdout from the command:
then continues with trying to get or hit files
Fetched 3,018 kB in 4s (681 kB/s)
Reading package lists...
Reading package lists...
Building dependency tree...
Reading state information...
The following extra packages will be installed:
apache2-mpm-worker apache2-utils apache2.2-bin apache2.2-common libapr1
libaprutil1 libaprutil1-dbd-sqlite3 libaprutil1-ldap ssl-cert
Suggested packages:
www-browser apache2-doc apache2-suexec apache2-suexec-custom
openssl-blacklist
The following NEW packages will be installed:
apache2 apache2-mpm-worker apache2-utils apache2.2-bin apache2.2-common
libapr1 libaprutil1 libaprutil1-dbd-sqlite3 libaprutil1-ldap ssl-cert
0 upgraded, 10 newly installed, 0 to remove and 155 not upgraded.
Need to get 1,845 kB of archives.
After this operation, 5,314 kB of additional disk space will be used.
Do you want to continue [Y/n]? Abort.
Stderr from the command:
stdin: is not a tty
i have even tried:
config.vm.network :forwarded_port, host: 3003, guest: 3000
And thats it failure, althought when i do go to localhost:3000 or that i get:
SSH-2.0-OpenSSH_5.9p1 Debian-5ubuntu1
Protocol mismatch.
I am on a MAC OSX 10.8.5
also the sections where it say
Do you want to continue [Y/n]?
i don't get to choose it automatically does this for me.

Can you try adding a '-y' to apt-get install? like: sudo apt-get -y install apache2 php5 libapache2-mod-php5 to overcome the 'Do you want to continue [Y/n]'? - nikhil

Related

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

wget is failing to get consul download from vagrant

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"

vagrant path to shell script windows

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 -

Vagrant provision not working

I have a problem with installing softwares using the vagrant provisions . I just tried to install git but I get this error :
==> default: stdin: is not a tty
==> default: git-email git-gui gitk gitweb diffutils-doc
==> default: The following NEW packages will be installed:
==> default: git git-man liberror-perl patch
==> default: 0 upgraded, 4 newly installed, 0 to remove and 179 not upgraded.
==> default: Need to get 6,730 kB of archives.
==> default: After this operation, 15.4 MB of additional disk space will be used.
==> default: Do you want to continue [Y/n]?
==> default: Abort.
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.
my Vargantfile looks so :
Vagrant.configure(2) do |config|
config.vm.box = "hashicorp/precise32"
config.vm.provision "shell", path: "bootstrap.sh"
end
and my bootstrap.sh contains exactly :
#!/usr/bin/env bash
sudo apt-get update
sudo apt-get install git
I tried it on mac and windows and get the same errors , I am using vagrant 1.7.2
You need to add the -y flag when installing stuff from your bootstrap file, otherwise the system will wait for a confirmation
sudo apt-get -y install git

Resources