I am running a 16.04 Ubuntu desktop machine using VirtualBox. This VM has Ansible 2.4.0 installed. I am trying to run an ad-hoc ansible command just to prove it works (I am doing an online course). To simulate a small server farm, I use lxc (linux containters) and have three of them running:
root@tomasz-VirtualBox:/home/tomasz/ansible# lxc-ls --fancy
NAME STATE AUTOSTART GROUPS IPV4 IPV6
db1 RUNNING 0 - 10.0.3.248 -
web1 RUNNING 0 - 10.0.3.110 -
web2 RUNNING 0 - 10.0.3.226 -
I can SSH to any of these servers, however when I try to run a one-off ansible command, for example:
root@tomasz-VirtualBox:/home/tomasz/ansible# ansible 10.0.3.248 -m ping -u ubuntu
I get the following errors, that no inventory has been matched:
[WARNING]: No inventory was parsed, only implicit localhost is available
[WARNING]: provided hosts list is empty, only localhost is available
[WARNING]: Could not match supplied host pattern, ignoring: 10.0.3.248
[WARNING]: No hosts matched, nothing to do
I am puzzled, to be honest, and as an Ansible novice, I have no idea how to move this forward. Seems such a simple issue, have not come across any similar thing here on stackoverflow. Many thanks for any hints!
I provide this host's IP address directly in the command. In this very case, according to my understanding, the inventory file is irrelevant.
Wrong. You specify host pattern, which should match hosts in your inventory. Inventory is a must for Ansible.
There's an option to specify "inline" inventory. For your case:
ansible all -i '10.0.3.248,' -m ping -u ubuntu
in this example: host pattern is all
, inventory is a list of a single host 10.0.3.248
.
Note comma at the end – it is important, this way Ansible understand that it is inline inventory, and not path to file.