oscar-stack / vagrant-config_builder

Configure Vagrant with structured data
Other
23 stars 19 forks source link

Dynamic YAML config by processing ERB first #24

Closed nanliu closed 10 years ago

nanliu commented 10 years ago

The yaml configuration files are processed by ERB first. This allows slightly more dynamic configs, such as support of environment variables for vagrant vm/provisioner settings:


---
  provisioner:
    - type: puppet
      manifest_file: <%= ENV['VAGRANT_MANIFEST'] || 'init.pp' >
nanliu commented 10 years ago

Not sure if there's a better solution (or if I'm using this plugin wrong). This would allow something like:

---
  provisioner:
    - type: puppet
      manifest_file: <%= ENV['VAGRANT_MANIFEST'] || 'init.pp' >
adrienthebo commented 10 years ago

I would rather ERB interpolated YAML be implemented as a separate loader; the loader layer is entirely pluggable so you can easily implement elaborate loaders without having to change the core implementations.

adrienthebo commented 10 years ago

For that matter, you could add a custom loader that inherits from the YAML loader, override that one method, and be done with that. However I don't want this to be a core behavior of the YAML loader.

nanliu commented 10 years ago

Sure, I updated the PR.

adrienthebo commented 10 years ago

Also, one of the purposes of this plugin was to get away from intertwined logic and data. If you need functionality like this, why not use a stock Vagrantfile?

nanliu commented 10 years ago

Originally I was using a stock Vagrantfile, then I wrote a wrapper to simplify the VM specification, but it was a bit clunky. The more I updated the wrapper, the closer it looked like something like this, so I thought it would be easier to add a few small things to this project. I really don't need to tweak the rest of the VM configuration, except occasionally the puppet agent environment or the puppet manifest file name.

Sharpie commented 10 years ago

I also believe that one of the driving purposes behind config_builder is to provide a logic-less way of configuring Vagrant. However, thhat does not have to preclude having an ERB layer that re-introduces logic --- as long as the two remain clearly and cleanly separated into different loaders.

nanliu commented 10 years ago

Yep, the PR was rewritten so the erb loader is yaml_erb, and the original yaml loader is left as is.

adrienthebo commented 10 years ago

Okay, I'm :+1:. Since this isn't as straightforward as pure YAML could you add some documentation to the class demonstrating the interpolation? Your first comment in this thread would be a great example of that.

nanliu commented 10 years ago

@adrienthebo, I've made some updates to the PR. Let me know what you think. I'll write another PR to update the project documentation (README, etc).

adrienthebo commented 10 years ago

Thanks for the contribution!