Ansible - vars_files plugin

Often, variables are created in a playbook, like this.

- hosts: all
    foo: hello
    bar: world


Instead of creating variables in a playbook, vars_files plugin can be used. In this example, the vars.yml file could be in the same directory as the playbook, or in the vars directory (vars/vars.yml).

- hosts: all
    - vars/vars.yml
    - debug:
        var: foo



The -e or --extra-vars command line optionExtra Variables in Tower and set_fact module will take precedence over vars_files.


Let's say vars.yml contains the following.

foo: Hello


Something like this should be returned.

TASK [debug]
ok: [] => {
    "foo": "Hello"


Add a Comment

We will never share your name or email with anyone. Enter your email if you would like to be notified when we respond to your comment.

Please enter 6f62d in the box below so that we can be sure you are a human.


Web design by yours truely - me, myself, and I   |   |