I am trying to fetch the variable value from group_vars but ansible is unable to locate it from the default location /etc/ansible. Here are the details.
Ansible Version
[admin@ansicontrol newvarsexample]$ ansible --version
ansible 2.9.18
config file = /etc/ansible/ansible.cfg
configured module search path = ['/home/admin/.ansible/plugins/modules', '/usr/share/ansible/plugins/modules']
ansible python module location = /usr/lib/python3.8/site-packages/ansible
executable location = /usr/bin/ansible
python version = 3.8.2 (default, Feb 28 2020, 00:00:00) [GCC 10.0.1 20200216 (Red Hat 10.0.1-0.8)]
Ansible Inventory file /etc/ansible/hosts:
[stack]
192.168.47.130
Ansible Playbook fedoragroupvarfile.yaml:
- hosts: all
remote_user: admin
tasks:
- name: Set OS distribution dependent variables
include_vars: "os_{{ ansible_facts['distribution'] }}.yaml"
- debug:
var: fedcharm
Ansible group_vars file /etc/ansible/group_vars/os_Fedora.yaml:
fedcharm: "This is Fedora 32 OS variable file"
Error
TASK [Set OS distribution dependent variables] *******************************************************************************
fatal: [192.168.47.130]: FAILED! => {"ansible_facts": {}, "ansible_included_var_files": [], "changed": false, "message": "Could not find or access 'os_Fedora.yaml'\nSearched in:\n\t/home/admin/practiceansible/newvarsexample/vars/os_Fedora.yaml\n\t/home/admin/practiceansible/newvarsexample/os_Fedora.yaml\n\t/home/admin/practiceansible/newvarsexample/vars/os_Fedora.yaml\n\t/home/admin/practiceansible/newvarsexample/os_Fedora.yaml on the Ansible Controller.\nIf you are using a module and expect the file to exist on the remote, see the remote_src option"}
Why does include_vars try to find the variables file in the current playbook's directory rather than the default /etc/ansible/group_vars location where the file is located.