On Fri, 29 Nov 2019 00:37:48 -0800 (PST)
"zhengqis...@sohu.com" <zhengqis...@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

-- 
You received this message because you are subscribed to the Google Groups 
"Ansible Project" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to ansible-project+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/ansible-project/20191129101436.4a840af1%40gmail.com.

Attachment: pgpKTBiaHmpQF.pgp
Description: OpenPGP digital signature

Reply via email to