Skip to content

global_vars

Note

Always use the FQCN (Fully Qualified Collection Name) arista.avd.global_vars when using this plugin.

Variable plugins to allow loading global_vars with less precedence than group_vars or host_vars

Synopsis

Loads variables from variable files specified in ansible.cfg or in the environment variable.

Assign the loaded variables to the 'all' inventory group.

Files are restricted by extension to one of .yaml, .json, .yml, or no extension.

Hidden files starting with \'.\' and backup files ending with \'\~\' are ignored.

Only applies to inventory sources that are existing paths.


ansible.cfg only example

1 - Enable the plugin in ansible.cfg - DO NOT REMOVE host_group_vars.

[defaults]

vars_plugins_enabled = arista.avd.global_vars, host_group_vars

[vars_global_vars]

paths = ../relative/path/to/my/global/vars/file/or/dir

2 - Run your playbook

ansible-playbook -i inventory.yml playbook.yml


ansible.cfg + environment variable example

1 - Enable the plugin in ansible.cfg - DO NOT REMOVE host_group_vars.

[defaults]

vars_plugins_enabled = arista.avd.global_vars, host_group_vars

2 - Run your playbook

ARISTA_AVD_GLOBAL_VARS_PATHS=../relative/path/to/my/global/vars/file/or/dir ansible-playbook -i inventory.yml playbook.yml

Requirements

The below requirements are needed on the host that executes this module.

  • This plugin should run at the `inventory` stage default before all other variable plugins to inject the variables before any group and host vars.

Parameters

Argument Type Required Default Value Restrictions Description
paths list True None List of relative paths relative to the inventory file.
If path is a directory, all the valid files inside are loaded alphabetically.
If the environment variable is set, it takes precedence over ansible.cfg.
stage any optional inventory Valid values:
- inventory
The stage during which executing the plugin. It could be 'inventory' or 'task'
Given the expected usage of this plugin at the beginning of the run. It is hard-coded to 'inventory'
_valid_extensions list optional [‘.yml’, ‘.yaml’, ‘.json’] Check all of these extensions when looking for 'variable' files, which should be YAML, JSON, or vaulted versions.
This affects vars_files, include_vars, inventory, and vars plugins, among others.

Authors

  • Arista Ansible Team (@aristanetworks)