On Fri, 29 Nov 2019 00:37:48 -0800 (PST)
"
zheng...@sohu.com" <
zheng...@sohu.com> wrote:
> - 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
> [...]
> [localhost]: FAILED! => {"msg": "The task includes an option with an
> undefined variable. The error was: 'inventory_dir' is undefined
Quoting from *Special variables*:
"inventory_dir: The directory of the inventory source in which the
inventory_hostname was first defined"
https://docs.ansible.com/ansible/latest/reference_appendices/special_variables.html#special-variables
The inventory hostname *localhost* hasn't been defined in any inventory
source hence *inventory_dir* is undefined.
It can be fixed for example by putting *localhost* into the *inventoryfile*
inventory file:
localhost
[master]
192.168.0.1
[all:vars]
host_yum_repos_file_path="{{inventory_dir}}/resources/yumrepos"
# (closing quotation is missing in the example)
Cheers,
-vlado