Skip to content

Instantly share code, notes, and snippets.

@UbuntuEvangelist
Forked from Remiii/README.md
Last active October 9, 2017 15:09
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save UbuntuEvangelist/9e38b0e45ad91b2f24bf88036544a833 to your computer and use it in GitHub Desktop.
Save UbuntuEvangelist/9e38b0e45ad91b2f24bf88036544a833 to your computer and use it in GitHub Desktop.
Setup Vagrant box (Ubuntu 14.04)

Setup Vagrant box (Ubuntu 14.04)

Introduction

This file discribe all the steps in order to setup a Vagrant box (using the Ansible Ubuntu simple Symfony App config - please refer to this repository for more info).

Requirements

Install the Vagrant box

Create the box

$ cd ~/vagrant/vm1
$ vagrant box add {title} {url}
$ vagrant init {title}

Sample box: Ubuntu Server Precise 12.04.4 amd64 (source) Kernel is ready for Docker (Docker not included) Contains Chef, Puppet

For example:

$ cd ~/vagrant/vm1
$ vagrant box add ubuntu_14_04_basebox https://oss-binaries.phusionpassenger.com/vagrant/boxes/latest/ubuntu-14.04-amd64-vbox.box
$ vagrant init ubuntu_14_04_basebox

Config the VM

Add the following lines in your VagrantFile

  config.vm.network "forwarded_port", guest: 20, host: 20020
  config.vm.network "forwarded_port", guest: 21, host: 20021
  config.vm.network "forwarded_port", guest: 22, host: 20022
  config.vm.network "forwarded_port", guest: 80, host: 20080
  for i in 1024..1048
    config.vm.network :forwarded_port, guest: i, host: i
  end
  config.vm.network "forwarded_port", guest: 3306, host: 23306

Run the VM

$ vagrant up

Ansible config

Clone the Ansible config

Clone the Ansible Ubuntu simple Symfony App.

$ cd ~/git
$ git clone https://github.com/Remiii/remiii-ansible-ubuntu-app-simple-symfony.git
$ cd remiii-ansible-ubuntu-app-simple-symfony

Config the Ansible config

*** WARNING: is just a sample, please ie. remiii-ansible-ubuntu-app-simple-symfony ***

Setup the vars in vars/myConfig.yml and add ansible_inventory_machinename file: More info here.

# ansible_inventory_machinename
machine ansible_ssh_host='127.0.0.1' ansible_ssh_port=20022

Copy the config dist file vars/myConfig.yml.dist

$ cp vars/myConfig.yml.dist vars/myConfig.yml
# pathToTheProject/vars/myConfig.yml
    ...
    rootPath: '~/git/remiii-ansible-ubuntu-app-simple-symfony'
    hostname: 'vm1.local'
    publicIpAddress: '127.0.0.1'
    ...

Add some files in the vars directory: More info here.

  • myGitUserMachineUserKey
  • myGitUserMachineUserKey.pub
  • mySSHPublicKey.pub
  • ...

Run the Ansible config

Exec the config:

$ ansible-playbook -i ansible_inventory_machinename --private-key=pathToYourVagrantPrivateKey -u vagrant ./myConfig.yml

Update etc/hosts config on your Host

$ sudo vi /etc/hosts

Add the following lines in your hosts /etc/hosts file:

###
# VM1
###
127.0.0.1    vm1.local sql.vm1.local apc.vm1.local website-sample.vm1.local website-sample1.vm1.local website-sample2.vm1.local foo.vm1.local

That's it!

Restart and login to the VM

$ cd ~/vagrant/vm1
$ vagrant reload
$ vargant ssh

License

MIT

Author

  • Rémi Barbe (aka Remiii)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment