|
|
|
@ -4,55 +4,57 @@ from __future__ import (absolute_import, division, print_function)
|
|
|
|
__metaclass__ = type
|
|
|
|
__metaclass__ = type
|
|
|
|
|
|
|
|
|
|
|
|
DOCUMENTATION = """
|
|
|
|
DOCUMENTATION = """
|
|
|
|
lookup: var
|
|
|
|
lookup: vars
|
|
|
|
author: Ansible Core
|
|
|
|
author: Ansible Core
|
|
|
|
version_added: "2.5"
|
|
|
|
version_added: "2.5"
|
|
|
|
short_description: Lookup templated value of variable
|
|
|
|
short_description: Lookup templated value of variables
|
|
|
|
description:
|
|
|
|
description:
|
|
|
|
- Retrieves the value of an Ansible variable.
|
|
|
|
- Retrieves the value of an Ansible variable.
|
|
|
|
options:
|
|
|
|
options:
|
|
|
|
_term:
|
|
|
|
_term:
|
|
|
|
description: The variable name to look up.
|
|
|
|
description: The variable names to look up.
|
|
|
|
required: True
|
|
|
|
required: True
|
|
|
|
default:
|
|
|
|
default:
|
|
|
|
description:
|
|
|
|
description:
|
|
|
|
- What to return when the variable is undefined.
|
|
|
|
- What to return if a variable is undefined.
|
|
|
|
- If no default is set, it will result in an error if the variable is undefined.
|
|
|
|
- If no default is set, it will result in an error if any of the variables is undefined.
|
|
|
|
"""
|
|
|
|
"""
|
|
|
|
|
|
|
|
|
|
|
|
EXAMPLES = """
|
|
|
|
EXAMPLES = """
|
|
|
|
- name: Show value of 'variablename'
|
|
|
|
- name: Show value of 'variablename'
|
|
|
|
debug: msg="{{ lookup('var', 'variabl' + myvar)}}"
|
|
|
|
debug: msg="{{ lookup('vars', 'variabl' + myvar)}}"
|
|
|
|
vars:
|
|
|
|
vars:
|
|
|
|
variablename: hello
|
|
|
|
variablename: hello
|
|
|
|
myvar: ename
|
|
|
|
myvar: ename
|
|
|
|
|
|
|
|
|
|
|
|
- name: Show default empty since i dont have 'variablnotename'
|
|
|
|
- name: Show default empty since i dont have 'variablnotename'
|
|
|
|
debug: msg="{{ lookup('var', 'variabl' + myvar, default='')}}"
|
|
|
|
debug: msg="{{ lookup('vars', 'variabl' + myvar, default='')}}"
|
|
|
|
vars:
|
|
|
|
vars:
|
|
|
|
variablename: hello
|
|
|
|
variablename: hello
|
|
|
|
myvar: notename
|
|
|
|
myvar: notename
|
|
|
|
|
|
|
|
|
|
|
|
- name: Produce an error since i dont have 'variablnotename'
|
|
|
|
- name: Produce an error since i dont have 'variablnotename'
|
|
|
|
debug: msg="{{ lookup('var', 'variabl' + myvar)}}"
|
|
|
|
debug: msg="{{ lookup('vars', 'variabl' + myvar)}}"
|
|
|
|
ignore_errors: True
|
|
|
|
ignore_errors: True
|
|
|
|
vars:
|
|
|
|
vars:
|
|
|
|
variablename: hello
|
|
|
|
variablename: hello
|
|
|
|
myvar: notename
|
|
|
|
myvar: notename
|
|
|
|
|
|
|
|
|
|
|
|
- name: find some 'prefixed vars' in loop
|
|
|
|
- name: find several related variables:
|
|
|
|
debug: msg="{{ lookup('var', 'ansible_play_' + item) }}"
|
|
|
|
debug: msg="{{ lookup('vars', 'ansible_play_hosts', 'ansible_play_batch', 'ansible_play_hosts_all') }}"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
- name: alternate way to find some 'prefixed vars' in loop
|
|
|
|
|
|
|
|
debug: msg="{{ lookup('vars', 'ansible_play_' + item) }}"
|
|
|
|
loop:
|
|
|
|
loop:
|
|
|
|
- hosts
|
|
|
|
- hosts
|
|
|
|
- batch
|
|
|
|
- batch
|
|
|
|
- hosts_all
|
|
|
|
- hosts_all
|
|
|
|
|
|
|
|
|
|
|
|
"""
|
|
|
|
"""
|
|
|
|
|
|
|
|
|
|
|
|
RETURN = """
|
|
|
|
RETURN = """
|
|
|
|
_value:
|
|
|
|
_value:
|
|
|
|
description:
|
|
|
|
description:
|
|
|
|
- valueof the variable requested
|
|
|
|
- valueof the variables requested.
|
|
|
|
"""
|
|
|
|
"""
|
|
|
|
|
|
|
|
|
|
|
|
from ansible.errors import AnsibleError, AnsibleUndefinedVariable
|
|
|
|
from ansible.errors import AnsibleError, AnsibleUndefinedVariable
|