I've finally unified these things, after many requests.
For those unfamiliar, assume your inventory file or script is:
/etc/ansible/hosts
This allows for two directories relative to them...
/etc/ansible/group_vars
/etc/ansible/host_vars
Then, for each group the host is in, you can put a YAML file at:
/etc/ansible/group_vars/groupname
(don't add an extension)
and can also do:
/etc/ansible/host_vars/hostname
(don't add an extension)
This allows you to manage your inventory variables, however nested or
detailed or structured (hashes of lists of hashes is totally fine!)
outside of your inventory file, keeping your inventory file nice and
simple.
Now previously, these variables were just available in playbooks, now
they are also usable in /usr/bin/ansible.
Remember when referencing variables on the shell command line, you'll
probably want to escape dollar signs so the shell doesn't eat them.
All the variables are merged such that child groups override as you
would expect.
--Michael