Importing variables into Vagrantfile via YAML

classic Classic list List threaded Threaded
2 messages Options
Reply | Threaded
Open this post in threaded view
|

Importing variables into Vagrantfile via YAML

William Saxton
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']

--
This mailing list is governed under the HashiCorp Community Guidelines - https://www.hashicorp.com/community-guidelines.html. Behavior in violation of those guidelines may result in your removal from this mailing list.
 
GitHub Issues: https://github.com/mitchellh/vagrant/issues
IRC: #vagrant on Freenode
---
You received this message because you are subscribed to the Google Groups "Vagrant" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
To view this discussion on the web visit https://groups.google.com/d/msgid/vagrant-up/bbbf683b-fd63-43fc-914f-358bc72fa000%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
Reply | Threaded
Open this post in threaded view
|

Re: Importing variables into Vagrantfile via YAML

William Saxton
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.

On Tuesday, May 23, 2017 at 8:30:25 PM UTC-4, William Saxton wrote:
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']

--
This mailing list is governed under the HashiCorp Community Guidelines - https://www.hashicorp.com/community-guidelines.html. Behavior in violation of those guidelines may result in your removal from this mailing list.
 
GitHub Issues: https://github.com/mitchellh/vagrant/issues
IRC: #vagrant on Freenode
---
You received this message because you are subscribed to the Google Groups "Vagrant" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
To view this discussion on the web visit https://groups.google.com/d/msgid/vagrant-up/9a69b152-bf6d-45a3-a660-db52097657f1%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.