in a playbook, how to get vars from a file that is in the inventiory ?
Assistant
In Ansible, you can use variables from files in your inventory by defining them in group_vars or host_vars directories. Here's a step-by-step guide on how to achieve this:
Directory Structure
First, ensure your inventory directory is structured properly. For example:
Ensure your playbook runs successfully, and you should see the values from the variables defined in your inventory files.
Here’s a breakdown of where variables will be sourced from:
group_vars/all - Variables accessible to all hosts.
group_vars/grou1.yml - Variables accessible to all hosts in group1.
host_vars/host1.yml - Variables accessible only to host1.
With this setup, Ansible automatically loads the variables from these files for the corresponding hosts or groups when executing the playbook. The playbook will use these variables like any other variables defined directly within it.