ansible version: 2.7.4systemos : centos7
playbook:
- name: local init
hosts: localhost
tasks:
- name: test
debug: msg=“{{ host_yum_repos_file_path }}”
inventory file:
[master]
192.168.0.1
[all:vars]
host_yum_repos_file_path="{{inventory_dir}}/resources/yumrepos
ansible-playbook -i inventoryfile planybook.yml
PLAY [local init] ************************************************************** TASK [Gathering Facts] ********************************************************* ok: [localhost] TASK [test] ******************************************************************** fatal: [localhost]: FAILED! => {“msg”: “The task includes an option with an undefined variable. The error was: ‘inventory_dir’ is undefined\n\nThe error appears to have been in ‘/media/sf_workspace/earth/ansible-k8s-tst/playbooks/testplay.yaml’: line 19, column 5, but may\nbe elsewhere in the file depending on the exact syntax problem.\n\nThe offending line appears to be:\n\n tasks:\n - name: test\n ^ here\n”} PLAY RECAP ********************************************************************* localhost : ok=1 changed=0 unreachable=0 failed=1