26
votes

I'm trying to execute my first remote shell script on Ansible. I've first generated and copied the SSH keys. Here is my yml file:

---
- name: Ansible remote shell
  hosts: 192.168.10.1
  user: myuser1
  become: true
  become_user: jboss
  tasks:
    - name: Hello server
      shell: /home/jboss/script.sh

When launching the playbook however, the outcome is "no hosts matched":

ansible-playbook setup.yml 

PLAY [Ansible remote shell
******************************************** 
skipping: no hosts matched

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

I've tried also using the host name (instead of the IP address), however nothing changed. Any help ?

3

3 Answers

42
votes

You need to define a host inventory.

The default path for this is /etc/ansible/hosts (as also stated by helloV).

For a minimal example you can also specify an inventory in the command line:

ansible-playbook setup.yml -i 192.168.10.1,

The trailing comma makes it a list, such that ansible parses it directy. Otherwise you can run

ansible-playbook setup.yml -i myinventory

where myinventory is a file listing your hosts.

13
votes

Ansible doesn't know anything about your host. If it is in dynamic inventory, you can pass the inventory script using -i option or edit /etc/ansible/hosts and add an entry for your host like:

[myhost]
192.168.10.1

and specify the host in the playbook as:

hosts: myhost
0
votes

we have to create an Inventory file in ansible there we need to give the location of IP address file for
create a file by name /ip.txt
And provide the path of the above-created file in your inventory