By default, Ansible will read
/etc/ansible/hosts as its default inventory file. Using this file is not recommended though. 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
You can run that command yourself, but first you gotta create an inventory file. 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 obviously look at the editor, but of course, you can also use your terminal to verify that
myhosts has been modified correctly, also:
So, now we can move on to running that command!