I noticed odd behavior with Ansible lookups a while back and, thinking it was a bug, reported it
here. Essentially, when I defined a lookup in host_vars, and referenced it in different ways from the same role, the lookup was executing with a different 'relative search path'. Brian told me this was by design, since my tasks different contexts. I'm not sure I understand the distinction though. Here is the role in question:
---
# Does lookup with respect to role
- name: direct reference
debug:
msg: "{{ users }}"
# Does lookup with respect to playbook
- name: reference through hostvars
debug:
msg: "{{ hostvars['SERVER_NAME']['users'] }}"
What's different about the context for these two tasks? How can I know a priori how a lookup is going to execute, without doing guess-and-check?
Thanks so much for your help!