I have two VMs one as ansible control machine and running playbook to perform action on second vm.
Following are files on ansible control machine
/etc/ansible/ansible.cfg
inventory = /etc/ansible/hosts
/etc/ansible/hosts
# My nodes
[my-group]
my1-node ansible_user=imran DB_SERVER=10.136.10.49 DB_USER=mydbusr
I tried following two ways to access variables but no success, but if i provide with command line like -e DB_SERVER=10.136.10.49. its working
myplaybook
---
- hosts: all
tasks:
- debug:
msg:
- "Database server {{DB_SERVER}}"
- "Database Username {{ hostvars['DB_USER'] }}"
Above is producing error
Update: I also run with verbose and its saying so its pointing to correct config, as i read due to vagrant sometime configuration is not pointed correctly.
Using /etc/ansible/ansible.cfg as config file
hostvars['DB_USER']makes no sense,hostvarscontains keys with host names, not variables. ForDB_SERVERthere is no reason to produce an error with the configuration you posted.