I'm have a box that uses ansible_local provisioning, which is defined in 
the Vagrant file included with the box:


config.vm.provision :ansible_local do |ansible|
  ansible_root = "/home/vagrant/provision"
  ansible.provisioning_path = ansible_root
  ansible.playbook = "#{ansible_root}/playbook.yml"
end




This works, but now I need to pass a variable to Ansible while provisioning 
a specific machine, i.e. I need to override the default provisioning 
settings.


At first I tried this (in the local Vagrantfile, which should override 
values in the box's Vagrantfile):

config.vm.provision :ansible_local do |ansible|
 ansible.extra_vars = {"develop_mode": true} 
end

This is no good, because Vagrant replaces the entire provision block 
instead of merging, and then complains that there's no playbook path 
defined. Let's try this:

config.vm.provision :ansible_local do |ansible|
  ansible_root = "/home/vagrant/provision"
  ansible.provisioning_path = ansible_root
  ansible.playbook = "#{ansible_root}/playbook.yml"
  ansible.extra_vars = {"develop_mode": true} 
end



Now, Vagrant can run the provisioner, but the `develop_mode` variable 
doesn't get set correctly. This is the output from Ansible:

TASK: [build | debug ] ************************************************** 
ok: [default] => {
    "var": {
        "develop_mode": "develop_mode"
    }
}



There are a couple of Vagrant 1.8.1 bugs 
<https://github.com/mitchellh/vagrant/issues/6726> about this, so here's a 
suggested workaround (using `raw_arguments` instead of `extra_vars`):

config.vm.provision :ansible_local do |ansible|
  ansible_root = "/home/vagrant/provision"
  ansible.provisioning_path = ansible_root
  ansible.playbook = "#{ansible_root}/playbook.yml"
  ansible.raw_arguments = ["--extra-vars", "develop_mode=true"]
end



Still no good, same Ansible output as before:

TASK: [build | debug ] ************************************************** 
ok: [default] => {
    "var": {
        "develop_mode": "develop_mode"
    }
}



Maybe I need to use an override in the local Vagrantfile?

config.vm.provider "virtualbox" do |vbox, override|
  override.vm.provision :ansible_local do |ansible|
    ansible_root = "/home/vagrant/provision"
    ansible.provisioning_path = ansible_root
    ansible.playbook = "#{ansible_root}/playbook.yml"
    ansible.raw_arguments = ["--extra-vars", "'develop_mode=true'"]
  end
end


No, still the same Ansible output as before. Is there a way to do what I'm 
trying to do?


FYI, here's the expected output as generated from running 
`ansible-playbook` directly on the VM:

TASK: [build | debug ] ************************************************** 
ok: [localhost] => { 
    "var": { 
        "develop_mode": "true" 
    } 
}



-- 
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 [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/vagrant-up/62a34ba4-a597-4d43-854f-bc8a582af836%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to