Ansible Module include vars: Difference between revisions

From NovaOrdis Knowledge Base
Jump to navigation Jump to search
 
(2 intermediate revisions by the same user not shown)
Line 2: Line 2:
* https://docs.ansible.com/ansible/latest/collections/ansible/builtin/include_vars_module.html#ansible-collections-ansible-builtin-include-vars-module
* https://docs.ansible.com/ansible/latest/collections/ansible/builtin/include_vars_module.html#ansible-collections-ansible-builtin-include-vars-module
=Internal=
=Internal=
* [[Ansible_Concepts#include_vars|Ansible Concepts]]
* [[Ansible_Concepts#include_vars|Ansible Concepts | Modules]]
* [[Ansible_Concepts#Places_where_to_Define_Variables|Ansible Concepts | Places where to Define Variables]]
 
=Overview=
=Overview=
The module Loads YAML/JSON variables dynamically from a file or directory, recursively, during task runtime. If loading a directory, the files are sorted alphabetically before being loaded.
The module Loads YAML/JSON variables dynamically from a file or directory, recursively, during task runtime. If loading a directory, the files are sorted alphabetically before being loaded.
=File Location=
<font color=darkgray>
* If executed as part of a role, "vars/some-var-file.yaml" is resolved to the role directory.
</font>
=Use Cases=
=Use Cases=
====Load Variables in a Playbook before Roles and Task Execution====
====Load Variables in a Playbook before Roles and Task Execution====

Latest revision as of 21:15, 5 July 2021

External

Internal

Overview

The module Loads YAML/JSON variables dynamically from a file or directory, recursively, during task runtime. If loading a directory, the files are sorted alphabetically before being loaded.

File Location

  • If executed as part of a role, "vars/some-var-file.yaml" is resolved to the role directory.

Use Cases

Load Variables in a Playbook before Roles and Task Execution

- name: some play
  hosts: localhost
  pre_tasks:
    - include_vars: 
        file: 'vars/some-vars.yaml' # Filename relative to the playbook root directory
  roles:
    - ...
  tasks:
    - ...