Answers: <p>The answer is in the warning you get:</p>
  <pre><code>[WARNING]: provided hosts list is empty, only localhost is available. Note that the implicit localhost does not match 'all'
  </code></pre>
  <p>When you use <code>hosts: all</code> in your playbook, <code>localhost</code> is not matched.</p>
  <p>If you want to run the playbook on localhost, you can do one of the following:</p>
  <ul>
  <li>Change your playbook to <code>hosts: localhost</code>.</li>
  <li>Explicitly provide an inventory file that has <code>localhost</code>.</li>
  </ul>
  <p>You can create an inventory file - <code>inventory.yml</code> with the contents:</p>
  <pre><code>all:
    hosts:
      localhost
  </code></pre>
  <p>and then pass this inventory file to ansible explicitly like this:</p>
  <p><code>$ ansible-playbook --connection=local -i inventory.yml playbook.yml</code></p>
  <p>You can find more information about inventory in the <a href="https://docs.ansible.com/ansible/2.7/user_guide/intro_inventory.html" rel="noreferrer">Ansible documentation</a>.</p>
  
Answers: CC BY-SA 4.0
Answers: 2020-09-18T23:23:43.250Z
Answers: Adding some context about why the test `ansible localhost -m ping -u root` worked ok: if you explicitly specify `localhost` then that _will_ match the implicit localhost in the default hosts file. You also aren't using `--connection=local` there. So this answer is the one you want, create a hosts file, it's almost always necessary.
Answers: hvindin
Answers: CC BY-SA 4.0
Answers: 2020-09-16T08:17:17.257Z
Answers: 2020-09-16T08:17:17.257Z
Answers: Ravi Mashru
Body: <p>I've tried a few <a href="https://gist.github.com/alces/caa3e7e5f46f9595f715f0f55eef65c1" rel="noreferrer">variations</a> on running <code>ansible</code> locally as a test case:</p>
  <pre><code>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: &quot;The hostname is {{ ansible_net_hostname }} and the OS is {{ ansible_net_version }}&quot;
  
  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 $ 
  </code></pre>
  <p>perhaps I need an additional configuration for the localhost loopback?</p>
  <p>Although I <em>can</em> ping localhost as:</p>
  <pre><code>nicholas $ 
  nicholas $ ansible localhost -m ping -u root
  127.0.0.1 | SUCCESS =&gt; {
      &quot;ansible_facts&quot;: {
          &quot;discovered_interpreter_python&quot;: &quot;/usr/bin/python3&quot;
      },
      &quot;changed&quot;: false,
      &quot;ping&quot;: &quot;pong&quot;
  }
  nicholas $ 
  </code></pre>
  
Tags: <ansible><yaml><orchestration><ansible-inventory><ubuntu>
Title: ansible error: skipping: no hosts matched
UserDisplayName: Nicholas Saunders
ThreadText: # ansible error: skipping: no hosts matched
  
  (Asked by: username_0 on 2020-09-15)
  
  I've tried a few [variations](https://gist.github.com/alces/caa3e7e5f46f9595f715f0f55eef65c1) on running `ansible` locally as a test case:
  
  ```
  username_0 $ 
  username_0 $ ls
  ansible.cfg  ansible.cfg.orig  first_playbook.yml  inventory.txt  playbook.yml
  username_0 $ 
  username_0 $ cat ansible.cfg
  [defaults]
  transport = local
  
  username_0 $ 
  username_0 $ 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 }}"
  
  username_0 $ 
  username_0 $ ansible --version
  ansible 2.9.6
    config file = /home/username_0/ansible/ansible.cfg
    configured module search path = ['/home/username_0/.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]
  username_0 $ 
  username_0 $ lsb_release -a
  No LSB modules are available.
  Distributor ID: Ubuntu
  Description:    Ubuntu 20.04 LTS
  Release:    20.04
  Codename:   focal
  username_0 $ 
  username_0 $ 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 *************************************************************************************************************************
  
  username_0 $ 
  
  ```
  
  perhaps I need an additional configuration for the localhost loopback?
  
  Although I *can* ping localhost as:
  
  ```
  username_0 $ 
  username_0 $ ansible localhost -m ping -u root
  127.0.0.1 | SUCCESS => {
      "ansible_facts": {
          "discovered_interpreter_python": "/usr/bin/python3"
      },
      "changed": false,
      "ping": "pong"
  }
  username_0 $ 
  
  ```
  
  **Tags:** ansible, yaml, orchestration, ansible-inventory, ubuntu
  
  
  ---
  
  ## 1 answers
  
  ### Answer by username_1 on 2020-09-16. Score: 6 | Accepted answer
  
  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](https://docs.ansible.com/ansible/2.7/user_guide/intro_inventory.html).
  
  > **Comments:**
  > **username_2**: Adding some context about why the test `ansible localhost -m ping -u root` worked ok: if you explicitly specify `localhost` then that _will_ match the implicit localhost in the default hosts file. You also aren't using `--connection=local` there. So this answer is the one you want, create a hosts file, it's almost always necessary.  
  
  ---
  
  