March 2019
Intermediate to advanced
412 pages
9h 49m
English
The vars_files key is a play directive. It defines a list of files to read from to load variable data. These files are read and parsed at the time the playbook itself is parsed. Just as with including tasks and handlers, the path is relative to the file referencing the file.
Here is an example play that loads variables from a file:
---
- name: vars
hosts: localhost
gather_facts: false
vars_files: - variables.yaml tasks: - name: a task debug: msg: "I am a {{ varname }}"
Now we need to create variables.yaml in the same directory as our playbook:
---varname: derp
Running the playbook will show that the name variable value is properly sourced from the variables.yaml file:
This is, of course, a very simple example, but it demonstrates ...
Read now
Unlock full access