I seem to be having an issue defining a variables in my /etc/ansible/hosts. When I run a playbook against a host in my inventory, it seems the variable are not read based on the error messages. For example, here it seems to not see the network os variable:
PLAY [Network Getting Started First Playbook - Change Hostname] ****************************************************************************************************************
TASK [Get old config for ios devices] ******************************************************************************************************************************************
fatal: [csr1]: FAILED! => {“msg”: “Unable to automatically determine host network os. Please manually configure ansible_network_os value for this host”}
As you rightly pointed out --limit works and -i don’t, as you reported you are getting desired output for ansible-inventory --host csr1 which indicates the inventory is already being picked up correctly.
To limit the hosts you target on a particular run we use –limit flag, -i on the other hand points to an inventory as a whole, not particular hosts.
you might get more clarity here.
Thank you Sagar. That gives me some clarity and puts me on the right path.
The link you shared is informative and certainly clarified some tips and flexibility for patterns with --limit. It does mention both methods of selecting a single host towards the bottom, but doesn’t provide as clear and concise statement of the difference as you did Namely that -i “points to an inventory as a whole” and will not reference existing inventory file or variables. To that end, I tried to be helpful and submitted a documentation PR that I think will be helpful to other new users: https://github.com/ansible/ansible/pull/77300