Importing variables into Vagrantfile via YAML

16 views
Skip to first unread message

William Saxton

unread,
May 23, 2017, 8:30:25 PM5/23/17
to Vagrant
So, I've populated a YAML file and loaded it into my Vagrantfile successfully (see below).   I know it works, because the "print" statement prints out the value.

When I try to assign that value to one of the node variables, though, the variable remains empty.

Any ideas?

config.yaml
-----------
os.username: 'myuser'


Vagrantfile
-----------
# -*- mode: ruby -*-
# vi: set ft=ruby :

require 'yaml'

current_dir    = File.dirname(File.expand_path(__FILE__))
config         = YAML.load_file("#{current_dir}/config.yaml")

# THIS WORKS!
print config['os.username']

Vagrant.configure("2") do |config|

  config.vm.define "pupstack" do |pupstack|

      # THIS DOESN'T WORK
      os.username = config['os.username']

William Saxton

unread,
May 23, 2017, 9:42:01 PM5/23/17
to Vagrant
I'm dumb.  Using the variable name "config" was an obvious conflict with:

    Vagrant.configure("2") do |config|

Changing it to a different name fixed it.
Reply all
Reply to author
Forward
0 new messages