Enable GUI on Vagrant Unbuntu 16.04 box

from: http://stackoverflow.com/questions/18878117/using-vagrant-to-run-virtual-machines-with-desktop-environment

  1. Get a basic Ubuntu image working. You should be able to boot it and vagrant ssh.
  2. Next, enable the VirtualBox display, which is off by default. Halt the VM and uncomment these lines in Vagrantfile:
    config.vm.provider :virtualbox do |vb|
      vb.gui = true
  3. Boot the VM and observe the new display window. Now you just need to install and start xfce4. Use vagrant ssh and:
    sudo apt-get install xfce4
    sudo startxfce4&

That’s it, you should be landed in a xfce4 session.

Update: For a better experience, I recommend these improvements:

  1. Don’t start the GUI as root. You really want to stay the vagrant user. To do this you need to permit anyone to start the GUI: sudo vim /etc/X11/Xwrapper.config and edit it to allowed_users=anybody.
  2. Next, install the VirtualBox guest tools before starting the GUI. This will give you a healthy screen resolution, integrated mouse, etc.
    $ sudo apt-get install -y xfce4 virtualbox-guest-dkms virtualbox-guest-utils virtualbox-guest-x11
    $ sudo VBoxClient-all
  3. Only now should you start the GUI as the vagrant user, with $ startxfce4&.

Update 2: Tried this today and the VBoxClient-all script isn’t always installed. If it’s missing, you can replace with the equivalent:

sudo VBoxClient --clipboard
sudo VBoxClient --draganddrop
sudo VBoxClient --display
sudo VBoxClient --checkhostversion
sudo VBoxClient --seamless



Vagrant.configure(2) do |config|
  # Ubuntu 15.10
  config.vm.box = "ubuntu/wily64"

  config.vm.provider "virtualbox" do |vb|
    # Display the VirtualBox GUI when booting the machine
    vb.gui = true

  # Install xfce and virtualbox additions
  config.vm.provision "shell", inline: "sudo apt-get update"
  config.vm.provision "shell", inline: "sudo apt-get install -y xfce4 virtualbox-guest-dkms virtualbox-guest-utils virtualbox-guest-x11"
  # Permit anyone to start the GUI
  config.vm.provision "shell", inline: "sudo sed -i 's/allowed_users=.*$/allowed_users=anybody/' /etc/X11/Xwrapper.config"

To start the vm

vagrant up

Login with username: vagrant, password: vagrant via the login prompt on the virtualbox GUI.

Start xfce


Use Vagrant vm as Ansible control machine

1. Create Vagrantfile as below:

Vagrant.configure(“2”) do |config|

config.ssh.insert_key = “false”

config.vm.define “ansible” do |ansible|
ansible.vm.box = “centos7”
ansible.vm.provision “shell”, path: “provision.sh”

config.vm.define “vagrant1” do |vagrant1|
vagrant1.vm.box = “ubuntu/trusty64”
vagrant1.vm.network “private_network”, ip: “”


2. The content of provision.sh

#!/usr/bin/env bash

echo “Add extra packages for pip”
sudo rpm -iUvh http://dl.fedoraproject.org/pub/epel/7/x86_64/e/epel-release-7-9.noarch.rpm
echo “update packages”
sudo yum -y update
echo “Install libraries”
sudo yum -y install python-pip python-devel python-lxml openssl-devel
echo “Update pip”
sudo pip install –upgrade pip
echo “Install ansible”
sudo pip install ansible
3. The ansible machine will be used to control the vagrant1 machine

4. After vagrant up, login into ansible machine by: vagrant ssh ansible
create private/public key and upload the public key to vagrant1 (make sure you can ping it first)

5. Add an entry to your /etc/hosts file: (optional)
[target server id] [hostname]
ex: testserv

6. create an Ansible inventory file hosts with the below content:
localhost ansible_connection=local (this line is added so that Ansible can provision local machine)
testserver ansible_host=testsrv ansible_user=vagrant

(Assume ‘testsrv’ is the hostname you add in your /etc/hosts file, if you didn’t add a hostname for the target server, then use its ip instead)

7. Run the following command to make sure Ansible can talk to both local and remote machine
ansible all -i hosts -m ping

How to fix Ansible failed to connect to remote machine due to publickey,password

Sometimes you will encounter an issue when connect to remote machine using Ansible, an example error is shown below:

[vagrant@localhost playbooks]$ ansible testserver -i hosts -m ping
testserver | UNREACHABLE! => {
“changed”: false,
“msg”: “Failed to connect to the host via ssh: Permission denied (publickey,password).\r\n”,
“unreachable”: true

The reason is you didn’t set up your private/public key properly, for example, if you try ssh username@remotehost, it will ask you for password, to fix it, follow the steps below (from: https://www.howtogeek.com/tips/bypass-ssh-logins-by-adding-your-key-to-a-remote-server-in-a-single-command/)

If you want to setup SSH keys to allow logging in without a password, you can do so with a single command. It’s quite easy.

The first thing you’ll need to do is make sure you’ve run the keygen command to generate the keys (if you have already generated keys, skip this step).

ssh-keygen -t rsa

Then use this command to push the key to the remote server, modifying it to match your server user name and host name.

cat ~/.ssh/id_rsa.pub | ssh user@hostname 'cat >> .ssh/authorized_keys'

You’ll have to enter your password the first time to copy the keys. After that, you should be able to login without a password, or even use scp or rsync without entering a password. You can test with this command:

ssh user@hostname

It’s definitely a lot easier than typing in a password all the time.

Set time in CentOS

From: https://www.cyberciti.biz/faq/howto-set-date-time-from-linux-command-prompt/

$ sudo timedatectl set-time YYYY-MM-DD

For example set the current date to 2015-12-01 (1st, Dec, 2015):
# timedatectl set-time '2015-12-01'
# timedatectl

Change timezone in CentOS

from: https://www.vultr.com/docs/setup-timezone-and-ntp-on-centos-6

Input the following command in your terminal:


As you see, the Vultr CentOS 6 x64 OS uses the UTC time by default. You can modify it to any time zone as you wish, but using the local timezone of the server’s physical location is a best practice.

If our server was running in China, then we would use the “Asia/Shanghai” time zone:

rm -rf /etc/localtime
ln -s /usr/share/zoneinfo/America/Torono /etc/localtime

You can navigate to the directory /usr/share/zoneinfo to find the appropriate time zone. There is an excellent resource on Wikipedia for timezone listings.

Input date again, you will find that the local system time has changed to CST (China Standard Time) GMT+0800.

Next, we will write the system time info into the hardware clock.

vi /etc/sysconfig/clock

Modify the content of this file as below.


Save and quit.


Write the system time into the hardware clock.

hwclock --systohc --localtime

Input hwclock to see the result.

A sample Vagrantfile to install ems, oracle, and bpm

# -*- mode: ruby -*-
# vi: set ft=ruby :

# All Vagrant configuration is done below. The “2” in Vagrant.configure
# configures the configuration version (we support older styles for
# backwards compatibility). Please don’t change it unless you know what
# you’re doing.
Vagrant.configure(“2”) do |config|
# The most common configuration options are documented and commented below.
# For a complete reference, please see the online documentation at
# https://docs.vagrantup.com.

# Every Vagrant development environment requires a box. You can search for
# boxes at https://atlas.hashicorp.com/search.
config.vm.box = “bento/centos-7.2”
config.vm.synced_folder “d:/software/dev_tools/BPM/bpm4.0/TIB_amx-bpm_4.0.0_linux24gl23_x86_64”, “/vagrant/bpm_install”
config.vm.synced_folder “d:/software/dev_tools/BPM/EMS8.2.2”, “/vagrant/ems_install”
config.vm.synced_folder “d:/software/dev_tools/oracle/12c/linux64/database”, “/vagrant/oracle_install”
# Disable automatic box update checking. If you disable this, then
# boxes will only be checked for updates when the user runs
# `vagrant box outdated`. This is not recommended.
# config.vm.box_check_update = false

# Create a forwarded port mapping which allows access to a specific port
# within the machine from a port on the host machine. In the example below,
# accessing “localhost:8080” will access port 80 on the guest machine.
# config.vm.network “forwarded_port”, guest: 80, host: 8080

# Create a private network, which allows host-only access to the machine
# using a specific IP.
config.vm.network “private_network”, ip: “”

# Create a public network, which generally matched to bridged network.
# Bridged networks make the machine appear as another physical device on
# your network.
config.vm.network “public_network”

# Share an additional folder to the guest VM. The first argument is
# the path on the host to the actual folder. The second argument is
# the path on the guest to mount the folder. And the optional third
# argument is a set of non-required options.
# config.vm.synced_folder “../data”, “/vagrant_data”

# Provider-specific configuration so you can fine-tune various
# backing providers for Vagrant. These expose provider-specific options.
# Example for VirtualBox:
config.vm.provider “virtualbox” do |vb|
vb.memory = “6144”

# View the documentation for the provider you are using for more
# information on available options.

# Define a Vagrant Push strategy for pushing to Atlas. Other push strategies
# such as FTP and Heroku are also available. See the documentation at
# https://docs.vagrantup.com/v2/push/atlas.html for more information.
# config.push.define “atlas” do |push|
# end

# Enable provisioning with a shell script. Additional provisioners such as
# Puppet, Chef, Ansible, Salt, and Docker are also available. Please see the
# documentation for more information about their specific syntax and use.
config.vm.provision “initialize”, type: “shell”, path: “scripts/initialize.sh”

#config.vm.provision “ems_install”, type: “shell”, path: “https://gist.githubusercontent.com/yonglai/caa8e8497a3640e23e93c61def9691ab/raw/f7e1daf08feb2abc98259574fdb1fea4960fb50f/ems_install.sh”
config.vm.provision “ems_install”, type: “shell”, path: “scripts/ems_install.sh”, privileged: false

config.vm.provision “ems_startup”, type: “shell”, path: “scripts/ems_startup.sh”

config.vm.provision “pre_oracle_install”, type: “shell”, path: “scripts/pre_oracle_install.sh”

config.vm.provision “oracle_install”, type: “shell”, path: “scripts/oracle_install.sh”

config.vm.provision “post_oracle_install”, type: “shell”, path: “scripts/post_oracle_install.sh”

config.vm.provision “bpm_install”, type: “shell”, path: “scripts/bpm_install.sh”, privileged: false

config.vm.provision “bpm_pre_config”, type: “shell”, path: “scripts/bpm_pre_config.sh”, privileged: false

config.vm.provision “bpm_config”, type: “shell”, path: “scripts/bpm_config.sh”, privileged: false

config.vm.provision “bpm_startup”, type: “shell”, path: “scripts/bpm_startup.sh”


To run:

vagrant up
vagrant provision –-provision-with initialize
vagrant reload
vagrant provision –-provision-with ems_install,ems_startup,pre_oracle_install,oracle_install
(wait for oracle install to complete)
vagrant provision –-provision-with post_oracle_install,bpm_studio_install,bpm_install,bpm_pre_config,bpm_config
vagrant provision –provision-with bpm_startup
vagrant provision –provision-with cleanup
vagrant provision –provision-with prepare_for_packaging