Skip to content

Instantly share code, notes, and snippets.

@phantomwhale
Created March 20, 2014 04:14
Show Gist options
  • Save phantomwhale/9657134 to your computer and use it in GitHub Desktop.
Save phantomwhale/9657134 to your computer and use it in GitHub Desktop.
Passing command line arguments into Vagrant to configure Ansible Provisioning
# 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
@karlskewes
Copy link

Thanks very much everyone! Using @geerlingguy's snippets above.

@gkedge
Copy link

gkedge commented Jul 24, 2021

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=""

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment