Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Select an option

  • Save eshell192007/010a0bb985b9070e3c44d76c9e60dbc6 to your computer and use it in GitHub Desktop.

Select an option

Save eshell192007/010a0bb985b9070e3c44d76c9e60dbc6 to your computer and use it in GitHub Desktop.

Revisions

  1. @tmclaugh tmclaugh renamed this gist May 19, 2014. 1 changed file with 0 additions and 0 deletions.
    File renamed without changes.
  2. @tmclaugh tmclaugh created this gist May 19, 2014.
    158 changes: 158 additions & 0 deletions gistfile1.txt
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,158 @@
    # -*- mode: ruby -*-
    # vi: set ft=ruby :
    #
    # TODO
    # - Current box is broken. Need to remove v.name setting hardcoding the box
    # name. This breaks parallelization.

    VG_ROLE = ENV['VG_ROLE'] || "hubspot::roles::role_basenode"
    INST_HOME = ENV['VG_INST_HOME'] || File.dirname(__FILE__)
    INST_NAME = ENV['VG_INST_NAME'] || INST_HOME.split(File::SEPARATOR)[-1]
    VM_BOX = ENV['VG_VM_BOX'] || "CentOS-6.5-x86_64-201312301757"
    HOSTNAME = ENV['VG_HOSTNAME'] || "%s.hubspot.local" % INST_NAME
    PUPPET_CLONE = ENV['VG_PUPPET_CLONE'] || INST_HOME.split(File::SEPARATOR)[0..-2].join(File::SEPARATOR)
    SSH_PRIVATE_KEY = ENV['VG_SSH_PRIVATE_KEY'] || "%s/vagrant/hubspot_vagrant_rsa" % PUPPET_CLONE
    VG_PUPPETMASTER_DIR = ENV['VG_PUPPETMASTER_DIR'] || "/etc/puppetmaster"
    FACTER_VARS = ENV['VG_FACTER_VARS'] || ''

    USER = ENV['USER']
    VG_PUPPETMASTER_LOCAL = '/etc/puppet-local'

    unless system('which librarian-puppet > /dev/null')
    puts "Puppet development environment not setup. Please run:"
    puts "#{PUPPET_CLONE}/tools/devsetup.sh"
    puts ""
    puts "Remember to run /usr/bin/librarian-puppet from your local clone afterwards in:"
    puts "#{PUPPET_CLONE}"
    abort
    end

    # Ensure librarian-puppet has been run.
    if not File.exists?("#{PUPPET_CLONE}/Puppetfile.lock")
    puts "You must run /usr/bin/librarian-puppet from '#{PUPPET_CLONE}'"
    abort
    end

    # 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 = VM_BOX
    # The url from where the 'config.vm.box' box will be fetched if it
    # doesn't already exist on the user's system.
    config.vm.box_url = "http://run.hubteam.com/vagrant/CentOS-6.5-x86_64-201312301757.box"

    # Hostname of new instance.
    config.vm.hostname = HOSTNAME

    # Location of insecure private key.
    config.ssh.private_key_path = SSH_PRIVATE_KEY

    # Create a forwarded port mapping which allows access to a specific port
    # within the machine from a port on the host machine. In the example below,
    # accessing "localhost:8080" will access port 80 on the guest machine.
    # config.vm.network :forwarded_port, guest: 80, host: 8080

    # If true, then any SSH connections made will enable agent forwarding.
    # Default value: false
    config.ssh.forward_agent = true

    # Share an additional folder to the guest VM. The first argument is
    # the path on the host to the actual folder. The second argument is
    # the path on the guest to mount the folder. And the optional third
    # argument is a set of non-required options.
    # config.vm.synced_folder "../data", "/vagrant_data"
    config.vm.synced_folder PUPPET_CLONE, "/etc/puppet-local", owner: "root", group: "root"

    # Provider-specific configuration so you can fine-tune various
    # backing providers for Vagrant. These expose provider-specific options.
    # Example for 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"]

    vb.customize ["modifyvm", :id, "--chipset", "ich9"]

    (1..4).each do |n|
    disk_path = "#{INST_HOME}/data-0-#{n}.vdi"
    vb.customize ["createhd", "--filename", disk_path, "--size", "4096"]
    vb.customize ["storageattach", :id, "--storagectl", "SATA", "--port", n, "--device", 0, "--type", "hdd", "--medium", disk_path]
    end

    # Faux-EBS
    max_vols = 9
    vb.customize ["storagectl", :id, "--add", "sata", "--name", "SATA-1", "--portcount", max_vols]
    (1..max_vols).each do |n|
    disk_path = "#{INST_HOME}/data-1-#{n}.vdi"
    vb.customize ["createhd", "--filename", disk_path, "--size", "4096"]
    vb.customize ["storageattach", :id, "--storagectl", "SATA-1", "--port", n, "--device", 0, "--type", "hdd", "--medium", disk_path]
    end

    end
    #
    # View the documentation for the provider you're using for more
    # information on available options.

    # Enable provisioning with Puppet stand alone. Puppet manifests
    # are contained in a directory path relative to this Vagrantfile.
    # You will need to create the manifests directory and a manifest in
    # the file hubspot-centos-64-x64.pp in the manifests_path directory.
    #
    # An example Puppet manifest to provision the message of the day:
    #
    # # group { "puppet":
    # # ensure => "present",
    # # }
    # #
    # # File { owner => 0, group => 0, mode => 0644 }
    # #
    # # file { '/etc/motd':
    # # content => "Welcome to your Vagrant-built virtual machine!
    # # Managed by Puppet.\n"
    # # }
    #
    # FIXME: Do this till we have a better way of cleaning things up. The
    # Puppetmaster data is persistent but the agent is not so the agent gets
    # an error

    config.vm.provision :puppet do |puppet|
    puppet.facter = {
    "hs_environment" => "qa",
    "environment" => "production",
    "data_center" => "local",
    "hs_puppetmaster_server" => "localhost",
    "os" => "centos6",
    "provider" => "virtualbox",
    "security_group" => "default",
    "vg_puppetmaster_dir" => VG_PUPPETMASTER_DIR,
    "vg_puppetmaster_local" => VG_PUPPETMASTER_LOCAL,
    "vg_role" => VG_ROLE,
    "creator" => USER,
    "description" => "Test server for role " + VG_ROLE
    }

    if defined? FACTER_VARS
    facter_extra = FACTER_VARS
    puppet.facter['facter_extra'] = facter_extra
    end

    puppet.manifests_path = ["vm", "#{VG_PUPPETMASTER_LOCAL}/vagrant/manifests"]
    puppet.manifest_file = "vagrant.pp"
    puppet.options = "--templatedir #{VG_PUPPETMASTER_LOCAL}/vagrant/templates"
    end

    config.vm.provision "puppet_server" do |puppet|
    puppet.puppet_server = "localhost"
    puppet.options = "--verbose"
    end

    end