By default, Ansible will read
/etc/ansible/hosts as its default inventory file. But you should maintain a different inventory file for each project that you have and pass it to both the
ansible-playbook commands using the
Here is an example of passing a custom inventory file to
ansible before running the
ansible all –i /path/to/inventory –m ping
In this tutorial you have access to one host named
host01. To let Ansible know about it, put its hostname in an inventory file.
1. We'll call our inventory file
myhosts, and you'll add one group called
echo "[group1]" > myhosts
2. Then, add the host to the group, while also passing the username to use for SSH access, as an inventory parameter.
echo "host01 ansible_ssh_user=ubuntu" >> myhosts
3. You can use your terminal to verify that
myhosts has been created:
So, now we can move on to running that command!