neufpas
neufpas

Reputation: 21

Host not found in Ansible inventory

I am trying to do some testing against a specific host with Ansible 2.5 but ansible can't figure out my inventory. I've either done something wrong or there's a bug. I've done this in the past but maybe something changed in 2.5

I have an inventory file specified like this:

localhost   ansible_connection=local
testhost   ansible_ssh_host=1.2.3.4

I have a playbook that runs totally fine if i just run it with ansible playbook.yml. It starts like this:

- hosts: localhost
  become: yes
  become_user: root
  become_method: sudo
  gather_facts: yes

If I run ansible-inventory --list I see both of my hosts listed as "ungrouped"

However, if I try to run my playbook against the remote host using ansible -l testhost playbook.yml it errors with the following:

 [WARNING]: Could not match supplied host pattern, ignoring: playbook.yml

ERROR! Specified hosts and/or --limit does not match any hosts

I can't figure out how to actually make Ansible run against my remote host.

Upvotes: 2

Views: 5189

Answers (2)

user2983509
user2983509

Reputation: 232

use simple method wherever you have to connect on local system? just specify connection : local to hosts block

- hosts: localhost
  connection : local
  become: yes
  become_user: root

Upvotes: 0

techraf
techraf

Reputation: 68439

Your playbook specifies:

hosts: localhost

It will not run on testfile regardless of the arguments you supply. --limit does not replace the hosts declaration.


As your hosts are ungrouped, you need to change this to:

hosts: all

Then you can use limit option to filter the hosts from the given target group.


You are also using wrong command to run an Ansible playbook, it should be ansible-playbook not ansible (and although the effect is the same, the latter does not fail with an error in such case).

Upvotes: 1

Related Questions