HiveBrain v1.2.0
Get Started
← Back to all entries
debugyamlMinor

ansible error: skipping: no hosts matched

Submitted by: @import:stackexchange-devops··
0
Viewed 0 times
errorhostsmatchedskippingansible

Problem

I've tried a few variations on running ansible locally as a test case:

nicholas $ 
nicholas $ ls
ansible.cfg  ansible.cfg.orig  first_playbook.yml  inventory.txt  playbook.yml
nicholas $ 
nicholas $ cat ansible.cfg
[defaults]
transport = local

nicholas $ 
nicholas $ cat playbook.yml 
---

- name: Network Getting Started First Playbook
  connection: network_cli
  gather_facts: false
  hosts: all
  tasks:

    - name: Get config for VyOS devices
      vyos_facts:
        gather_subset: all

    - name: Display the config
      debug:
        msg: "The hostname is {{ ansible_net_hostname }} and the OS is {{ ansible_net_version }}"

nicholas $ 
nicholas $ ansible --version
ansible 2.9.6
  config file = /home/nicholas/ansible/ansible.cfg
  configured module search path = ['/home/nicholas/.ansible/plugins/modules', '/usr/share/ansible/plugins/modules']
  ansible python module location = /usr/lib/python3/dist-packages/ansible
  executable location = /usr/bin/ansible
  python version = 3.8.2 (default, Jul 16 2020, 14:00:26) [GCC 9.3.0]
nicholas $ 
nicholas $ lsb_release -a
No LSB modules are available.
Distributor ID: Ubuntu
Description:    Ubuntu 20.04 LTS
Release:    20.04
Codename:   focal
nicholas $ 
nicholas $ ansible-playbook --connection=local  playbook.yml
[WARNING]: provided hosts list is empty, only localhost is available. Note that the implicit localhost does not match 'all'

PLAY [Network Getting Started First Playbook] **************************************************************************************
skipping: no hosts matched

PLAY RECAP *************************************************************************************************************************

nicholas $


perhaps I need an additional configuration for the localhost loopback?

Although I can ping localhost as:

```
nicholas $
nicholas $ ansible localhost -m ping -u root
127.0.0.1 | SUCCESS => {
"ansible_facts": {
"discovered_interpreter_python": "/usr/bin/python3"

Solution

The answer is in the warning you get:

[WARNING]: provided hosts list is empty, only localhost is available. Note that the implicit localhost does not match 'all'


When you use hosts: all in your playbook, localhost is not matched.

If you want to run the playbook on localhost, you can do one of the following:

  • Change your playbook to hosts: localhost.



  • Explicitly provide an inventory file that has localhost.



You can create an inventory file - inventory.yml with the contents:

all:
  hosts:
    localhost


and then pass this inventory file to ansible explicitly like this:

$ ansible-playbook --connection=local -i inventory.yml playbook.yml

You can find more information about inventory in the Ansible documentation.

Code Snippets

[WARNING]: provided hosts list is empty, only localhost is available. Note that the implicit localhost does not match 'all'
all:
  hosts:
    localhost

Context

StackExchange DevOps Q#12411, answer score: 6

Revisions (0)

No revisions yet.