-
-
Save phantomwhale/9657134 to your computer and use it in GitHub Desktop.
# with a space, this doesn't work... | |
$ ANSIBLE_ARGS='-t elasticsearch' vagrant provision | |
==> default: Running provisioner: ansible... | |
ERROR: tag(s) not found in playbook: elasticsearch. possible values: apache,common,elasticsearch,java,passenger,postgresql,ruby | |
Ansible failed to complete successfully. Any error output should be visible above. Please fix these errors and try again. | |
# without the space, it now works... | |
$ ANSIBLE_ARGS='-telasticsearch' vagrant provision | |
==> default: Running provisioner: ansible... | |
PLAY [web] ******************************************************************** | |
... |
VAGRANTFILE_API_VERSION = "2" | |
Vagrant.configure(VAGRANTFILE_API_VERSION) do |config| | |
config.vm.box = "precise64" | |
config.vm.box_url = "http://files.vagrantup.com/precise64.box" | |
config.vm.provision "ansible" do |ansible| | |
ansible.playbook = "config/ansible/site.yml" | |
ansible.extra_vars = { | |
"ansible_ssh_user" => "vagrant", | |
} | |
ansible.raw_arguments = ENV['ANSIBLE_ARGS'] | |
end | |
end |
For anyone else who comes along looking for how to pass arguments to Ansible via the Vagrant command line:
If you set ansible.raw_arguments = ENV[ANSIBLE_ARGS].to_s.split(':')
you can put multiple arguments in the variable, seperated by :
. to_s
turns a Nil value into the empty string, so you can leave ANSIBLE_ARGS
empty without having split
throw a fit.
Use shell split algorithm:
ansible.raw_arguments = Shellwords.shellsplit(ENV['ANSIBLE_ARGS']) if ENV['ANSIBLE_ARGS']
It works like a charm.
The whitespace issue seems to be fixed now. I tested in ansible 1.9
I think this is the third time I've come back here so just wanted to finally star the gist.
Also, here's what I have working:
config.vm.provision "ansible" do |ansible|
ansible.playbook = "main.yml"
ansible.raw_arguments = Shellwords.shellsplit(ENV['ANSIBLE_ARGS']) if ENV['ANSIBLE_ARGS']
end
# CLI command.
ANSIBLE_ARGS='--extra-vars "some_var=value"' vagrant up
This allows the playbook to work either way (with or without any ANSIBLE_ARGS
).
Thanks to @generalov for the tip on shellsplit!
Thanks very much everyone! Using @geerlingguy's snippets above.
I have to provision a VM on Windows using ansible_local
. Pity me. And, I am PS impaired also so for those of my lot, this might help:
PS> $env:ANSIBLE_ARGS='--tags "start_of_day"'; vagrant up --provision
The same entry in the Vagrant file shared by @geerlingguy applies. The application of the ANSIBLE_ARGS
on a Windows PS (compared to the Linux line shared) is that ANSIBLE_ARGS is permanent for the terminal session.
To get that same behavior to not have an env var linger, you would have to unset it after the vagrant
command:
PS> $env:ANSIBLE_ARGS='--tags "start_of_day"'; vagrant up --provision; $env:ANSIBLE_ARGS=""
As demonstrated below, this whitespace bug is in childprocess library, which is used by Vagrant.
output (tested with childprocess 0.5.1):
ERROR: tag(s) not found in playbook: elasticsearch. possible values: elasticsearch
Note that you can alternatively use
--tags=elasticsearch
, which might look a bit nicer than-telasticsearch
.