I have an inventories/path/hosts.yml
file that has something like this, for example.
all:
children:
host1:
10.10.10.1
host2:
10.10.10.2
Then I set this up in group_vars
to set the credentials for each host.
group_vars/host1.yml
--------------------
ansible_user: admin
ansible_password: password1
group_vars/host2.yml
--------------------
ansible_user: admin
ansible_password: password2
This all works if the user runs ansible-playbook
using the host name, that is, the credentials in their respective group_vars
get picked up.
$ ansible-playbook -i inventories/path/hosts.yml -e var_host=host1 my_playbook.yml
How can I set this up so the respective credentials are picked up when the user passes the IP address of the host instead of label?
$ ansible-playbook -i 10.10.10.1, -e var_host=10.10.10.1 my_playbook.yml