Notice! This post is more than a year old. It may be outdated.
I have a playbook which will be run on the Ansible host.
---
- name: My play
hosts: localhost
connection: local
roles:
- list of roles
Running the play from the command line using ansible-playbook
I got the result that I expected. But when I use Vagrant to provision a virtual machine using Ansible provisioner, the play that should have been executed on the Ansible host was skipped altogether.
PLAY [My play] ****
skipping: no hosts matched
From what I understand, this is caused by Vagrant Ansible provisioner always setting the --limit
argument. I can reproduce the same issue by executing the playbook using ansible-playbook
and setting the --limit
argument explicitly.
$ ansible-playbook -i inventory/dev/hosts play.yml --limit all
Workaround
In your Vagrantfile
add the following line to your Ansible provisioner configuration
ansible.limit = 'all,localhost'