Ansible - vars_files plugin

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

---
- hosts: all
  vars:
    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_files:
    - vars/vars.yml
  tasks:
    - debug:
        var: foo

 

AVOID TROUBLE

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: [server1.example.com] => {
    "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.




Comments

Web design by yours truely - me, myself, and I   |   jeremy.canfield@freekb.net   |