"skipping: no hosts matched" issue with Vagrant and Ansible
Solution 1
It could help to post your Vagrantfile and your ansible inventory file.
Are you using the default ansible provider of vagrant?
did you specify the
inventory_path
?
config.vm.provision :ansible do |ansible| ansible.playbook = "provisioning/playbook.yml" ansible.inventory_path = "provisioning/ansible_hosts" end
- Are you launching it the through the a vagrant ssh with
--connection=local
try a /etc/ansible/hosts
[webserver1] 127.0.0.1 ansible_connection=local
- Are you using the ansibleLocal provider / vagrant plugin?
Solution 2
Make sure you're running ansible-playbook command instead of pure ansible command.
Solution 3
I think you can also do this without a hosts file, by assigning the Ansible groups in your Vagrant file.
If you don't have multiple machines in your Vagrant file your box will probably be called "default" and you will be able to add multiple Ansible groups with the following code.
Code:
config.vm.provision "ansible" do |ansible|
ansible.groups = {
"webservers" => ["default"],
"dev_enviroment" => ["default"]
}
ansible.playbook = "provisioning/playbook.yml"
end
Solution 4
Changing hosts to "all" worked for me.
---
- hosts: all
user: vagrant
sudo: yes
Solution 5
The first thing that jumps out at me is that the syntax on the head of your playbook file is incorrect, (it has extra dashes where it shouldn't). It should look like this instead:
---
- hosts: webservers
user: vagrant
sudo: yes
Dubby
Updated on January 14, 2021Comments
-
Dubby over 3 years
I have installed Vagrant, VirtualBox and Ansible and trying to run provision over one host but it always returns "skipping: no hosts matched"
The head of my playbook file looks like this:
--- - hosts: webservers user: vagrant sudo: yes
and my
/etc/ansible/hosts
file looks like this:[webservers] webserver1
I tried putting the IP address there but had the same result. I have added my ssh key to the server and added webserver1 host to both
.ssh/config
and/etc/hosts
.I can
ssh vagrant@webserver1
fine without being prompted for a password, thanks to using the ssh key.What am I missing here?
- Host: Debian 7.2
- Client machine: Debian 7
- Virtualbox: 4.1.18
- Vangrantup: 1.4.1
- Ansible: 1.5