Skip to content

Instantly share code, notes, and snippets.

@rdhyee
Last active August 29, 2015 13:59
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save rdhyee/10935909 to your computer and use it in GitHub Desktop.
Save rdhyee/10935909 to your computer and use it in GitHub Desktop.
a template Vagrantfile that adds ansible provisioning, along with accompanying ansible playbook. To run the ansible playbook: ansible-playbook -i .vagrant/provisioners/ansible/inventory/vagrant_ansible_inventory --private-key=~/.vagrant.d/insecure_private_key -u vagrant hello.yml
#!/bin/sh
ansible-playbook -vvvv -i .vagrant/provisioners/ansible/inventory/vagrant_ansible_inventory --private-key=.vagrant/machines/hello_django/virtualbox/private_key -u vagrant $1
- name: Hello Ansible
hosts: box001
sudo: no
tasks:
- name: Hello server
shell: date > now.txt
# -*- mode: ruby -*-
# vi: set ft=ruby :
# Vagrantfile API/syntax version. Don't touch unless you know what you're doing!
VAGRANTFILE_API_VERSION = "2"
Vagrant.configure(VAGRANTFILE_API_VERSION) do |config|
# All Vagrant configuration is done here. The most common configuration
# options are documented and commented below. For a complete reference,
# please see the online documentation at vagrantup.com.
# Every Vagrant virtual environment requires a box to build off of.
config.vm.box = "ubuntu/trusty64"
# you can replace box001 with another name
config.vm.define 'box001' do |node|
node.vm.provision 'ansible' do |ansible|
# http://bertvv.github.io/vagrant-presentation/#/vagrant-configuration
# "define directive is important to make automatic inventory work"
# I wish I could comment out the following line to allow for
# .vagrant/provisioners/ansible/inventory/vagrant_ansible_inventory
# to be calculated w/o running any ansible playbook -- but no luck
ansible.playbook = 'hello.yml'
end
end
# config.vm.network "forwarded_port", guest: 80, host: 8080
# config.vm.network "private_network", ip: "192.168.33.10"
# config.vm.synced_folder "data", "vagrant_data"
# virtualbox
# config.vm.provider "virtualbox" do |vb|
# # Don't boot with headless mode
# vb.gui = true
#
# # Use VBoxManage to customize the VM. For example to change memory:
# vb.customize ["modifyvm", :id, "--memory", "1024"]
# end
#
end
@rdhyee
Copy link
Author

rdhyee commented Apr 16, 2014

To run the ansible playbook:

 ansible-playbook -i .vagrant/provisioners/ansible/inventory/vagrant_ansible_inventory --private-key=~/.vagrant.d/insecure_private_key -u vagrant hello.yml

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment