h2ik Hell If I Know

Dynamic Vagrant Shares

At SugarCRM, we are deploying Vagrant stacks as part of the DevOps Initiative. How ever we ran into a few problems with defining shares. Since no two engineers work the same or have the same setup we couldn't define shares that were hard coded in the Vagrantfile. We had to come up with a way to do shares that end user could customize easily. While looking for solutions someone pointed out that the Vagrantfile is just Ruby and we could use YAML to define the shares. The seed had been planted and this is the bit of code we came up with.

Place this bit of code inside the Vagrantfile:

VAGRANTFILE_API_VERSION = '2'
Vagrant.configure(VAGRANTFILE_API_VERSION) do |config|
  #....
  # Start Dynamic Shares
  if File.exists?('share.yaml')
    require 'yaml'
    yaml = YAML.load_file(Dir.pwd + '/share.yaml')
    yaml.each do |share|
      share_group = 'vagrant'
      share_group = 'apache' if share['target'] =~ /www\/html/
      config.vm.synced_folder share['source'], share['target'], create: true, owner: 'vagrant', group: share_group
    end
  end
  # End Dynamic Shares
  #...
end

share.yaml example:

-
  source: '/Users/jwhitcraft/Sites'
  target: '/var/www/html/Sites'
-
  source: '/Users/jwhitcraft/Documents'
  target: '/var/www/html/Docs'

This method allows the user to create a share.yaml next to the Vagrantfile, which it will then be picked up and converted into the config.vm.synced_folder attribute when then vagrant up or vagrant reload command is issued.

Hope this helps others!

Blogging is hard

One would think that I would have a lot to share with the world, but I find typing out what is in my head very hard. I'm not sure what I can do about it.

I think I'm going to try and force myself to write a new blog post every two weeks in hope that it will become easier for me to do.

While I'm not sure what the topics might be, they will mostly be technical in nature maybe some on video games. Who really knows...

Till next time!

New Year, New Site

It's been well over a year since I last updated this site.

Yes it has really been that long, while life has become more chaotic with the coming of the twins, Elijah and Blake, I havn't been able to update the site like I was in 2012.

Now that the boys are almost 2 years old, I feel that I can start writing in my blog again. I'm moving away from WordPress to Jekyll. I won't bore you with the details, but it just came down to I spend the time to manage WordPress or do I goto something more static and easier to use. Never fear though, my old site and all of it's posts are still there.

There is still more to do on this site as there currently is no commenting system or a sharing system, but I'm gonig to continue to work and get those features added ASAP.