ansible.builtin.vars (v2.8.18) — lookup

Lookup templated value of variables

| "added in version" 2.5 of ansible.builtin"

Authors: Ansible Core

Install Ansible via pip

Install with pip install ansible==2.8.18

Description

Retrieves the value of an Ansible variable.

Usage examples

  • Success
    Steampunk Spotter scan finished with no errors, warnings or hints.
- name: Show value of 'variablename'
  debug: msg="{{ lookup('vars', 'variabl' + myvar)}}"
  vars:
    variablename: hello
    myvar: ename
  • Success
    Steampunk Spotter scan finished with no errors, warnings or hints.
- name: Show default empty since i dont have 'variablnotename'
  debug: msg="{{ lookup('vars', 'variabl' + myvar, default='')}}"
  vars:
    variablename: hello
    myvar: notename
  • Success
    Steampunk Spotter scan finished with no errors, warnings or hints.
- name: Produce an error since i dont have 'variablnotename'
  debug: msg="{{ lookup('vars', 'variabl' + myvar)}}"
  ignore_errors: True
  vars:
    variablename: hello
    myvar: notename
  • Success
    Steampunk Spotter scan finished with no errors, warnings or hints.
- name: find several related variables
  debug: msg="{{ lookup('vars', 'ansible_play_hosts', 'ansible_play_batch', 'ansible_play_hosts_all') }}"
  • Success
    Steampunk Spotter scan finished with no errors, warnings or hints.
- name: alternate way to find some 'prefixed vars' in loop
  debug: msg="{{ lookup('vars', 'ansible_play_' + item) }}"
  loop:
    - hosts
    - batch
    - hosts_all

Inputs

    
_terms:
    description: The variable names to look up.
    required: true

default:
    description:
    - What to return if a variable is undefined.
    - If no default is set, it will result in an error if any of the variables is undefined.

Outputs

_value:
  description:
  - value of the variables requested.