Skip to content

Instantly share code, notes, and snippets.

@JoelBCarter
Last active January 1, 2016 18:18
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 JoelBCarter/ae2d2b16d98322596f5f to your computer and use it in GitHub Desktop.
Save JoelBCarter/ae2d2b16d98322596f5f to your computer and use it in GitHub Desktop.
A Vagrantfile for running the [Learn to manage a basic Ubuntu web application](https://learn.chef.io/manage-a-web-app/ubuntu/) Chef tutorial locally
# -*- mode: ruby -*-
# vi: set ft=ruby :
module LocalCommand
class Config < Vagrant.plugin("2", :config)
attr_accessor :command
end
class Plugin < Vagrant.plugin("2")
name "shell_local"
config(:shell_local, :provisioner) do
Config
end
provisioner(:shell_local) do
Provisioner
end
end
class Provisioner < Vagrant.plugin("2", :provisioner)
def provision
result = system "#{config.command}"
end
end
end
Vagrant.configure(2) do |config|
config.vm.define 'node', primary: true do |node|
node.vm.box = 'ubuntu/trusty64'
# Bridged networks make the machine appear as another physical device on
# your network.
node_ip = '10.0.0.101'
node.vm.network 'public_network',
bridge: 'Dell GigabitEthernet',
ip: node_ip
# The hostname the machine should have
node.vm.hostname = 'chef-client'
node.vm.provider 'virtualbox' do |vb|
vb.gui = false
vb.name = node.vm.hostname
vb.cpus = 2
vb.memory = '1024'
end
# If we previously Vagrant up'd this IP, there'll be a signature for
# it in our .ssh/known_hosts file for a box that no longer exists since
# Vagrant generates a new key each time we Vagrant up. So we'll go
# ahead and remove that here
node.vm.provision 'remove-old-ssh-key',
type: 'shell_local',
command: "ssh-keygen -R #{node_ip}"
# Uninstall Chef (older version 11.8.2-2 is currently pre-installed on
# the base box)
node.vm.provision 'remove-chef-client', type: :shell, inline: <<-SHELL
dpkg -P chef
dpkg -P chef-zero
SHELL
end
end
@JoelBCarter
Copy link
Author

A Vagrantfile for running the Learn to manage a basic Ubuntu web application Chef tutorial locally. Be sure to replace the name of the NIC bridge: 'Dell GigabitEthernet' with your own NIC name. After you vagrant up, you should be able to run all the provisioning steps in the tutorial using the vagrant provided identity file as such:
knife ssh 10.0.0.101 'sudo chef-client' --manual-list --ssh-user vagrant --identity-file ".\.vagrant\machines\node\virtualbox\private_key"

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