I have one query regarding ansible-playbook command, I kept my inventory file and YAML playbook in same directory , when i run
ansible-playbook playbook.yml → I am getting message “No matching hosts” .
But when i explicitly mention a dynamic inventory command like
ansible-playbook -i inventory playbook.yml → then it successfully executes the desired action, now my query is :
what is the difference between >> ansible-playbook playbook.yml & >> ansible-playbook -i inventory playbook.yml while i have my inventory file and playbook.yml file under same directory ?
@Aashiqahamed, When you run ansible-playbook Ansible looks in several places to find the inventory. It looks in these places, in this order, until it finds an inventory reference:
Inventory actually defined in the default inventory file: /etc/ansible/hosts.
Notes and References:
Any of these references can be to a directory or can use wildcards to collect multiple inventory files in the same directory.
INI-style inventory files do not need file extensions.
Inventory can be formatted in INI, YAML, JSON, and more (depending on plugins).
The ansible-inventory command is really handy to get an idea of what Ansible thinks is the inventory. You can also use this command to print out the inventory in different formats.