Jan 15, 2015 Tag: Vagrant
Ongoing attempt to collect links and documentation about Vagrant. Will be updated as needed.
Updated on Nov 10, 2015
Navigate this page:
Ansible, Vagrant, Sphinx
2015-08-25
The procedure to get a current Debian Jessie up and running:
# go somewhere
cd ~/htdocs
# start with new folder
mkdir Vagrant.sphinx.typo3.loc
# go there
cd ~/htdocs/Vagrant.sphinx.typo3.loc
vagrant init debian/jessie64
vagrant up --provider virtualbox
vagrant ssh
Copy the public key of my host machine into the vagrant box for user ‘vagrant’ without giving ‘vagrant’ a password:
ssh -i .vagrant/machines/default/virtualbox/private_key \
-p 2222 vagrant@localhost 'cat >> ~/.ssh/authorized_keys' \
< ~/.ssh/id_rsa.pub
Or copy all public keys with a wildcard:
ssh -i .vagrant/machines/default/virtualbox/private_key \
-p 2222 vagrant@localhost 'cat >> ~/.ssh/authorized_keys' \
< ~/.ssh/id_*.pub
Or give ‘vagrant’ a password. Then you can simply copy you public key like this:
ssh-copy-id -p 2222 vagrant@localhost
Now we can log in with our normal key:
# login with normal private key
ssh -p 2222 vagrant@localhost
In my /etc/hosts
I have a line:
sphinx.typo3.loc 192.168.2.11
And my ‘Vagrantfile’ looks like this meaning that the virtual machine will appear as 192.168.2.11 on my host machine:
# -*- mode: ruby -*-
# vi: set ft=ruby :
Vagrant.configure(2) do |config|
config.vm.box = "debian/jessie64"
config.vm.network "private_network", ip: "192.168.2.11"
config.vm.provider "virtualbox" do |vb|
vb.memory = "1024"
vb.cpus = 4
end
end
This make it even nicer an I cann ssh into the virtual machine like so:
ssh vagrant@sphinx.typo3.loc
Now let’s tell Ansible that we refer to that machine with the name ‘sphinx’:
sudo gedit /etc/ansible/hosts
And add the machine:
[sphinx]
127.0.0.1:2222 ansible_ssh_user=vagrant
This should work as well - but I didn’t try:
[sphinx]
sphinx.typo3.loc ansible_ssh_user=vagrant
Run a check to see what machines are available:
ansible all -m ping -u vagrant
# or
ansible sphinx -m ping -u vagrant
# or, since we've set ansible_ssh_user=vagrant
ansible all -m ping
127.0.0.1 | success >> {
"changed": false,
"ping": "pong"
}
Now, let’s go to the ‘sphinx’ playbook:
# go somewhere
cd ~/Repositories/git.typo3.org/Teams
# clone repository
git clone git://git.typo3.org/Teams/Documentation.git
# go there
cd ~/Repositories/git.typo3.org/Teams/Documentation
And play the playbook. I’m not hundred percent sure at the moment whether the ‘-u vagrant’ is necessary:
ansible-playbook -s install.yml -u vagrant
# This is the default ansible 'hosts' file.
#
# It should live in /etc/ansible/hosts
#
# - Comments begin with the '#' character
# - Blank lines are ignored
# - Groups of hosts are delimited by [header] elements
# - You can enter hostnames or ip addresses
# - A hostname/ip can be a member of multiple groups
[sphinx]
127.0.0.1:2222 ansible_ssh_user=vagrant
# This line would be nicer. But I haven't tried yet.
# sphinx.typo3.loc ansible_ssh_user=vagrant
Run a new provisioning:
REINSTALL=true vagrant provision t3o-web
Install a plugin to make vagrant update the hosts file automatically::
sudo vagrant plugin install vagrant-hostsupdater
Some more:
vagrant ssh t3o-web
vagrant ssh t3o-solr
For me:
sudo dpkg -i vagrant_1.7.4_x86_64.deb
# verify vagrant is there:
vagrant
# find package name (= 'vagrant')
dpkg -l | grep vagrant
packagename=vagrant
# remove package
sudo dpkg -r $packagename
# reconfigure
sudo dpkg-reconfigure $packagename
Some Vagrant example commands:
vagrant
vagrant --help
vagrant box --help
vagrant box list
vagrant box remove Jessie
ansible-playbook \
-i .vagrant/provisioners/ansible/inventory/vagrant_ansible_inventory \
--private-key=~/.vagrant.d/insecure_private_key. \
-u vagrant playbook.yml
ansible all -m ping -i .vagrant/provisioners/ansible/inventory/vagrant_ansible_inventory --private-key=~/.vagrant.d/insecure_private_key
# for vagrant >= 1.7.0:
--private-key=.vagrant/machines/default/virtualbox/private_key