Ansible Variable Lens
Hover over an Ansible variable and see its value. No more searching through
files to find out what {{ app_port }} actually is.
The problem
You are reading a playbook and see {{ app_port }}. What is its value? It could
be set in the role defaults, in group_vars, in the play, in a vars file, or in
a set_fact. You have to search, open files, and remember which one wins.
The solution
Put your mouse on the variable. The extension finds every place it is set,
applies the same rules Ansible uses, and shows you the answer:
app_port = 8443
play vars · site.yml:12
Click the file name to jump there.
What you get
Hover shows the value and where it comes from.
Ctrl+click (Cmd+click on Mac) jumps to where the variable is set. This also
works on role names and on file paths such as include_tasks: install.yml.
Shift+F12 lists every place the variable is used.
Autocomplete suggests variable names while you type inside {{ }}.
A yellow underline warns you when a variable is not set anywhere, which
usually means a typo.
When there is more than one answer
Sometimes the value depends on something the editor cannot know, such as which
group the host is in. Then you see every possible value:
app_host
"aap-controller" group controller · group_vars/controller.yml:3
"aap-hub" group hub · group_vars/hub.yml:3
The same happens inside a role that is used by several playbooks:
app_port
8080 via other.yml · group_vars/all.yml:2
8443 via site.yml · play vars · site.yml:5
If all the answers are the same, you just see the one value.
Variables that only exist while the playbook runs
A variable from register or set_fact has no value in any file. The hover
shows which task creates it, so you can jump to that task:
app_status
gets its value at runtime, registered by command task "Get status" · site.yml:9
Variables built from other variables
app_url = "https://{{ app_host }}:{{ app_port }}"
group_vars/all.yml:3
filled in: "https://aap-controller:8443"
Getting started
- Install the extension.
- Open a folder that contains Ansible playbooks.
- Hover over a variable.
There is nothing to configure. The extension finds your playbooks, roles,
group_vars and host_vars on its own, wherever they are in the folder. It
works together with the Red Hat Ansible extension.
Settings
You do not need any of these. They are there if you want to change something.
| Setting |
Default |
What it does |
ansibleVariableLens.hover.enabled |
true |
Turn the hover on or off. |
ansibleVariableLens.completion.enabled |
true |
Turn autocomplete on or off. |
ansibleVariableLens.diagnostics.undefinedVariables |
true |
Turn the yellow "not defined" warning on or off. |
ansibleVariableLens.diagnostics.ignoreVariables |
[] |
Variable names that should never get a warning. Patterns work too, for example survey_*. Handy for variables that come from AAP surveys or extra vars. |
ansibleVariableLens.hover.maxAlternatives |
10 |
How many possible values one hover may list. |
ansibleVariableLens.hover.maxValueLines |
15 |
How many lines of a long value are shown. |
ansibleVariableLens.rolesPaths |
[] |
Extra folders that contain roles. |
ansibleVariableLens.exclude |
[] |
Folders or files to skip, for example **/molecule/**. |
If something looks out of date, run Ansible Variable Lens: Rebuild index from the
command palette.
What it cannot do
The extension reads your files. It does not run Ansible. That means:
- It does not read inventory files or inventories stored in AAP. It knows your
groups from the file names in
group_vars.
- It cannot know extra vars (
-e, AAP surveys) or facts gathered from a host.
- It does not look inside roles or collections installed from Galaxy.
- It does not run Jinja filters. The "filled in" line only replaces plain
{{ variable }} references.
- Vault values are shown as
vault-encrypted. They are never decrypted.
For developers
npm install
npm test # unit tests
npm run test:integration # tests inside a real VS Code
npm run build
Press F5 in VS Code to try the extension in a second window.
License
MIT