Background: I frequently end up working on different laptops running on different operating systems. This means I waste a lot of time re-installing the same programs and applications. I've decided to try and automate this using Vagrant and Ansible.
Problem: As I want this build to be deployable on a range of operating systems I want Vagrant to spin up a simple ubuntu/trusty64
box, and Ansible to be installed and execute on the Ubuntu box, however I'm having trouble with the Ansible hosts. I've read the Ansible docs and have read about inventory however haven't found it very clear how these work or where this should be defined in my setup. For reference I'm new to both Vagrant and Ansible but have experience with VirtualBox. Any help would be much appreciated
Vagrantfile:
# -*- mode: ruby -*-"
# vi: set ft=ruby :
# vagrant plugin install vagrant-ansible-local
VAGRANTFILE_API_VERSION = "2"
$ansible_install_script = <<SCRIPT
if ! which ansible >/dev/null; then
apt-get update -y
apt-get install -y software-properties-common
apt-add-repository -y ppa:ansible/ansible
apt-get update -y
apt-get install -y ansible
fi
SCRIPT
Vagrant.configure(VAGRANTFILE_API_VERSION) do |config|
config.vm.define "dev-machine", primary: true do |machine|
machine.vm.box = "ubuntu/trusty64"
machine.vm.hostname = 'local.dev-machine.box'
machine.vm.network :private_network, :ip => '10.20.1.2'
machine.vm.provider "virtualbox" do |vb|
vb.gui = true
vb.memory = "8192"
end # vb
machine.vm.provision "shell", inline: $ansible_install_script
machine.vm.provision "ansibleLocal" do |ansible|
ansible.guest_folder = "/vagrant-ansible"
ansible.raw_arguments = "--inventory=/vagrant-ansbile/ansible_hosts"
ansible.playbook = "playbook.yml"
ansible.limit = "local.dev-machine.box"
end # ansible
end # machine
end # config
playbook.yml:
---
- hosts: all
become: yes
become_method: sudo
tasks:
- name: Check Ubuntu 14.04 running
assert:
that:
- ansible_distribution == 'Ubuntu'
- ansible_distribution_release == 'trusty'
- name: update apt cache
apt: update_cache=yes
- name: install git
apt: name=git-core state=latest
- name: Install Python 3.4
apt: name={{items}} state=latest
with_items:
- python
- python-dev
- python-virtualenv
- python-setuptools
- python-pip