mirror of https://github.com/ansible/ansible.git
document tests (#78685)
Document the builtin test plugins Co-authored-by: Felix Fontein <felix@fontein.de>pull/78727/head
parent
fcfdca8e7d
commit
77ba025a13
@ -0,0 +1,23 @@
|
||||
DOCUMENTATION:
|
||||
name: abs
|
||||
author: Ansible Core
|
||||
version_added: "2.5"
|
||||
short_description: is the path absolute
|
||||
aliases: [is_abs]
|
||||
description:
|
||||
- Check if the provided path is absolute, not relative.
|
||||
- An absolute path expresses the location of a filesystem object starting at the filesystem root and requires no context.
|
||||
- A relative path does not start at the filesystem root and requires a 'current' directory as a context to resolve.
|
||||
options:
|
||||
_input:
|
||||
description: A path.
|
||||
type: path
|
||||
|
||||
EXAMPLES:
|
||||
is_path_absolute: "{{ '/etc/hosts' is abs }}}"
|
||||
relative_paths: "{{ all_paths | reject('abs') }}"
|
||||
|
||||
RETURN:
|
||||
_value:
|
||||
description: Returns C(True) if the path is absolute, C(False) if it is relative.
|
||||
type: boolean
|
@ -0,0 +1,23 @@
|
||||
DOCUMENTATION:
|
||||
name: all
|
||||
author: Ansible Core
|
||||
version_added: "2.4"
|
||||
short_description: are all conditions in a list true
|
||||
description:
|
||||
- This test checks each condition in a list for truthiness.
|
||||
- Same as the C(all) Python function.
|
||||
options:
|
||||
_input:
|
||||
description: List of conditions, each can be a boolean or conditional expression that results in a boolean value.
|
||||
type: list
|
||||
elements: raw
|
||||
required: True
|
||||
EXAMPLES: |
|
||||
varexpression: "{{ 3 == 3 }}"
|
||||
# are all statements true?
|
||||
{{ [true, booleanvar, varexpression] is all }}
|
||||
|
||||
RETURN:
|
||||
_value:
|
||||
description: Returns C(True) if all elements of the list were True, C(False) otherwise.
|
||||
type: boolean
|
@ -0,0 +1,23 @@
|
||||
DOCUMENTATION:
|
||||
name: any
|
||||
author: Ansible Core
|
||||
version_added: "2.4"
|
||||
short_description: is any conditions in a list true
|
||||
description:
|
||||
- This test checks each condition in a list for truthiness.
|
||||
- Same as the C(any) Python function.
|
||||
options:
|
||||
_input:
|
||||
description: List of conditions, each can be a boolean or conditional expression that results in a boolean value.
|
||||
type: list
|
||||
elements: raw
|
||||
required: True
|
||||
EXAMPLES: |
|
||||
varexpression: "{{ 3 == 3 }}"
|
||||
# are all statements true?
|
||||
{{ [false, booleanvar, varexpression] is any}}
|
||||
|
||||
RETURN:
|
||||
_value:
|
||||
description: Returns C(True) if any element of the list was true, C(False) otherwise.
|
||||
type: boolean
|
@ -0,0 +1,49 @@
|
||||
DOCUMENTATION:
|
||||
name: contains
|
||||
author: Ansible Core
|
||||
version_added: "2.4"
|
||||
short_description: does the list contain this element
|
||||
description:
|
||||
- Checks the supplied element against the input list to see if it exists within it.
|
||||
options:
|
||||
_input:
|
||||
description: List of elements to compare.
|
||||
type: list
|
||||
elements: raw
|
||||
required: True
|
||||
_contained:
|
||||
description: Element to test for.
|
||||
type: raw
|
||||
required: True
|
||||
EXAMPLES: |
|
||||
# simple expression
|
||||
{{ listofthings is contains('this') }}
|
||||
|
||||
# as a selector
|
||||
- action: module=doessomething
|
||||
when: lacp_groups|selectattr('interfaces', 'contains', 'em1')|first).master
|
||||
vars:
|
||||
lacp_groups:
|
||||
- master: lacp0
|
||||
network: 10.65.100.0/24
|
||||
gateway: 10.65.100.1
|
||||
dns4:
|
||||
- 10.65.100.10
|
||||
- 10.65.100.11
|
||||
interfaces:
|
||||
- em1
|
||||
- em2
|
||||
|
||||
- master: lacp1
|
||||
network: 10.65.120.0/24
|
||||
gateway: 10.65.120.1
|
||||
dns4:
|
||||
- 10.65.100.10
|
||||
- 10.65.100.11
|
||||
interfaces:
|
||||
- em3
|
||||
- em4
|
||||
RETURN:
|
||||
_value:
|
||||
description: Returns C(True) if the specified element is contained in the supplied sequence, C(False) otherwise.
|
||||
type: boolean
|
@ -0,0 +1,21 @@
|
||||
DOCUMENTATION:
|
||||
name: directory
|
||||
author: Ansible Core
|
||||
version_added: "2.5"
|
||||
short_description: does the path resolve to an existing directory
|
||||
description:
|
||||
- Check if the provided path maps to an existing directory on the controller's filesystem (localhost).
|
||||
options:
|
||||
_input:
|
||||
description: A path.
|
||||
type: path
|
||||
|
||||
EXAMPLES:
|
||||
vars:
|
||||
my_etc_hosts_not_a_dir: "{{ '/etc/hosts' is directory}}"
|
||||
list_of_files: "{{ list_of_paths | reject('directory') }}"
|
||||
|
||||
RETURN:
|
||||
_value:
|
||||
description: Returns C(True) if the path corresponds to an existing directory on the filesystem on the controller, c(False) if otherwise.
|
||||
type: boolean
|
@ -0,0 +1,22 @@
|
||||
DOCUMENTATION:
|
||||
name: exists
|
||||
author: Ansible Core
|
||||
version_added: "2.5"
|
||||
short_description: does the path exist, follow symlinks
|
||||
description:
|
||||
- Check if the provided path maps to an existing filesystem object on the controller (localhost).
|
||||
- Follows symlinks and checks the target of the symlink instead of the link itself, use the C(link) or C(link_exists) tests to check on the link.
|
||||
options:
|
||||
_input:
|
||||
description: a path
|
||||
type: path
|
||||
|
||||
EXAMPLES:
|
||||
vars:
|
||||
my_etc_hosts_exists: "{{ '/etc/hosts' is exist }}"
|
||||
list_of_local_files_to_copy_to_remote: "{{ list_of_all_possible_files | select('exists') }}"
|
||||
|
||||
RETURN:
|
||||
_value:
|
||||
description: Returns C(True) if the path corresponds to an existing filesystem object on the controller (after following symlinks), C(False) if otherwise.
|
||||
type: boolean
|
@ -0,0 +1,24 @@
|
||||
DOCUMENTATION:
|
||||
name: falsy
|
||||
author: Ansible Core
|
||||
version_added: "2.10"
|
||||
short_description: Pythonic false
|
||||
description:
|
||||
- This check is a more Python version of what is 'false'.
|
||||
- It is the opposite of 'truthy'.
|
||||
options:
|
||||
_input:
|
||||
description: An expression that can be expressed in a boolean context.
|
||||
type: string
|
||||
required: True
|
||||
convert_bool:
|
||||
description: Attempts to convert the result to a strict Python boolean vs normally acceptable values (C(yes)/C(no), C(on)/C(off), C(0)/C(1), etc).
|
||||
type: bool
|
||||
default: false
|
||||
EXAMPLES: |
|
||||
thisisfalse: '{{ "any string" is falsy }}'
|
||||
thisistrue: '{{ "" is falsy }}'
|
||||
RETURN:
|
||||
_value:
|
||||
description: Returns C(False) if the condition is not "Python truthy", C(True) otherwise.
|
||||
type: boolean
|
@ -0,0 +1,22 @@
|
||||
DOCUMENTATION:
|
||||
name: file
|
||||
author: Ansible Core
|
||||
version_added: "2.5"
|
||||
short_description: does the path resolve to an existing file
|
||||
description:
|
||||
- Check if the provided path maps to an existing file on the controller's filesystem (localhost)
|
||||
aliases: [is_file]
|
||||
options:
|
||||
_input:
|
||||
description: A path.
|
||||
type: path
|
||||
|
||||
EXAMPLES:
|
||||
vars:
|
||||
my_etc_hosts_is_a_file: "{{ '/etc/hosts' is file }}"
|
||||
list_of_files: "{{ list_of_paths | select('file') }}"
|
||||
|
||||
RETURN:
|
||||
_value:
|
||||
description: Returns C(True) if the path corresponds to an existing file on the filesystem on the controller, C(False) if otherwise.
|
||||
type: boolean
|
@ -0,0 +1 @@
|
||||
abs.yml
|
@ -0,0 +1 @@
|
||||
directory.yml
|
@ -0,0 +1 @@
|
||||
file.yml
|
@ -0,0 +1 @@
|
||||
link.yml
|
@ -0,0 +1 @@
|
||||
same_file.yml
|
@ -0,0 +1 @@
|
||||
mount.yml
|
@ -0,0 +1 @@
|
||||
nan.yml
|
@ -0,0 +1 @@
|
||||
subset.yml
|
@ -0,0 +1 @@
|
||||
superset.yml
|
@ -0,0 +1,21 @@
|
||||
DOCUMENTATION:
|
||||
name: link
|
||||
author: Ansible Core
|
||||
version_added: "2.5"
|
||||
short_description: does the path reference existing symbolic link
|
||||
aliases: [islink]
|
||||
description:
|
||||
- Check if the provided path maps to an existing symlink on the controller's filesystem (localhost).
|
||||
options:
|
||||
_input:
|
||||
description: A path.
|
||||
type: path
|
||||
|
||||
EXAMPLES:
|
||||
ismyhostsalink: "{{ '/etc/hosts' is link}}"
|
||||
list_of_symlinks: "{{ list_of_paths | select('link') }}"
|
||||
|
||||
RETURN:
|
||||
_value:
|
||||
description: Returns C(True) if the path corresponds to an existing symlink on the filesystem on the controller, C(False) if otherwise.
|
||||
type: boolean
|
@ -0,0 +1,21 @@
|
||||
DOCUMENTATION:
|
||||
name: link_exists
|
||||
author: Ansible Core
|
||||
version_added: "2.5"
|
||||
short_description: does the path exist, no follow
|
||||
description:
|
||||
- Check if the provided path maps to an existing symlink on the controller's filesystem (localhost).
|
||||
- Does not follow symlinks, so it only verifies that the link itself exists.
|
||||
options:
|
||||
_input:
|
||||
description: A path.
|
||||
type: path
|
||||
|
||||
EXAMPLES:
|
||||
ismyhostsalink: "{{ '/etc/hosts' is link_exists}}"
|
||||
list_of_symlinks: "{{ list_of_paths | select('link_exists') }}"
|
||||
|
||||
RETURN:
|
||||
_value:
|
||||
description: Returns C(True) if the path corresponds to an existing filesystem object on the controller, C(False) if otherwise.
|
||||
type: boolean
|
@ -0,0 +1,32 @@
|
||||
DOCUMENTATION:
|
||||
name: match
|
||||
author: Ansible Core
|
||||
short_description: Does string match regular expression from the start
|
||||
description:
|
||||
- Compare string against regular expression using Python's match function,
|
||||
this means the regex is automatically anchored at the start of the string.
|
||||
options:
|
||||
_input:
|
||||
description: String to match.
|
||||
type: string
|
||||
required: True
|
||||
pattern:
|
||||
description: Regex to match against.
|
||||
type: string
|
||||
required: True
|
||||
ignorecase:
|
||||
description: Use case insenstive matching.
|
||||
type:
|
||||
default: False
|
||||
multiline:
|
||||
description: Match against mulitple lines in string.
|
||||
type: boolean
|
||||
default: False
|
||||
EXAMPLES: |
|
||||
url: "https://example.com/users/foo/resources/bar"
|
||||
foundmatch: url is match("https://example.com/users/.*/resources")
|
||||
nomatch: url is match("/users/.*/resources")
|
||||
RETURN:
|
||||
_value:
|
||||
description: Returns C(True) if there is a match, C(False) otherwise.
|
||||
type: boolean
|
@ -0,0 +1,22 @@
|
||||
DOCUMENTATION:
|
||||
name: mount
|
||||
author: Ansible Core
|
||||
version_added: "2.5"
|
||||
short_description: does the path resolve to mount point
|
||||
description:
|
||||
- Check if the provided path maps to a filesystem mount point on the controller (localhost).
|
||||
aliases: [is_mount]
|
||||
options:
|
||||
_input:
|
||||
description: A path.
|
||||
type: path
|
||||
|
||||
EXAMPLES:
|
||||
vars:
|
||||
ihopefalse: "{{ '/etc/hosts' is mount }}"
|
||||
normallytrue: "{{ '/tmp' is mount }}"
|
||||
|
||||
RETURN:
|
||||
_value:
|
||||
description: Returns C(True) if the path corresponds to a mount point on the controller, C(False) if otherwise.
|
||||
type: boolean
|
@ -0,0 +1,20 @@
|
||||
DOCUMENTATION:
|
||||
name: nan
|
||||
author: Ansible Core
|
||||
version_added: "2.5"
|
||||
short_description: is this not a number (NaN)
|
||||
description:
|
||||
- Whether the input is a special floating point number called L(not a number, https://en.wikipedia.org/wiki/NaN).
|
||||
aliases: [is_file]
|
||||
options:
|
||||
_input:
|
||||
description: Possible number representation or string that can be converted into one.
|
||||
type: raw
|
||||
required: true
|
||||
EXAMPLES:
|
||||
isnan: "{{ '42' is nan }}"
|
||||
|
||||
RETURN:
|
||||
_value:
|
||||
description: Returns C(True) if the input is NaN, C(False) if otherwise.
|
||||
type: boolean
|
@ -0,0 +1,37 @@
|
||||
DOCUMENTATION:
|
||||
name: regex
|
||||
author: Ansible Core
|
||||
short_description: Does string match regular expression from the start
|
||||
description:
|
||||
- Compare string against regular expression using Python's match or search functions.
|
||||
options:
|
||||
_input:
|
||||
description: String to match.
|
||||
type: string
|
||||
required: True
|
||||
pattern:
|
||||
description: Regex to match against.
|
||||
type: string
|
||||
required: True
|
||||
ignorecase:
|
||||
description: Use case insenstive matching.
|
||||
type: boolean
|
||||
default: False
|
||||
multiline:
|
||||
description: Match against multiple lines in string.
|
||||
type: boolean
|
||||
default: False
|
||||
match_type:
|
||||
description: Decide which function to be used to do the matching.
|
||||
type: string
|
||||
choices: [match, search]
|
||||
default: search
|
||||
|
||||
EXAMPLES: |
|
||||
url: "https://example.com/users/foo/resources/bar"
|
||||
foundmatch: url is regex("example\.com/\w+/foo")
|
||||
|
||||
RETURN:
|
||||
_value:
|
||||
description: Returns C(True) if there is a match, C(False) otherwise.
|
||||
type: boolean
|
@ -0,0 +1,24 @@
|
||||
DOCUMENTATION:
|
||||
name: same_file
|
||||
author: Ansible Core
|
||||
version_added: "2.5"
|
||||
short_description: compares two paths to see if they resolve to the same filesystem object
|
||||
description: Check if the provided paths map to the same location on the controller's filesystem (localhost).
|
||||
aliases: [is_file]
|
||||
options:
|
||||
_input:
|
||||
description: A path.
|
||||
type: path
|
||||
required: true
|
||||
_path2:
|
||||
description: Another path.
|
||||
type: path
|
||||
required: true
|
||||
|
||||
EXAMPLES: |
|
||||
amionelevelfromroot: "{{ '/etc/hosts' is same_file('../etc/hosts') }}"
|
||||
|
||||
RETURN:
|
||||
_value:
|
||||
description: Returns C(True) if the paths correspond to the same location on the filesystem on the controller, C(False) if otherwise.
|
||||
type: boolean
|
@ -0,0 +1,33 @@
|
||||
DOCUMENTATION:
|
||||
name: search
|
||||
author: Ansible Core
|
||||
short_description: Does string match a regular expression
|
||||
description:
|
||||
- Compare string against regular expression using Python's C(search) function.
|
||||
options:
|
||||
_input:
|
||||
description: String to match.
|
||||
type: string
|
||||
required: True
|
||||
pattern:
|
||||
description: Regex to match against.
|
||||
type: string
|
||||
required: True
|
||||
ignorecase:
|
||||
description: Use case insenstive matching.
|
||||
type:
|
||||
default: False
|
||||
multiline:
|
||||
description: Match against mulitple lines in string.
|
||||
type: boolean
|
||||
default: False
|
||||
|
||||
EXAMPLES: |
|
||||
url: "https://example.com/users/foo/resources/bar"
|
||||
foundmatch: url is search("https://example.com/users/.*/resources")
|
||||
alsomatch: url is search("users/.*/resources")
|
||||
|
||||
RETURN:
|
||||
_value:
|
||||
description: Returns C(True) if there is a match, C(False) otherwise.
|
||||
type: boolean
|
@ -0,0 +1,28 @@
|
||||
DOCUMENTATION:
|
||||
name: subset
|
||||
author: Ansible Core
|
||||
version_added: "2.4"
|
||||
aliases: [issubset]
|
||||
short_description: is the list a subset of this other list
|
||||
description:
|
||||
- Validate if the first list is a sub set (is included) of the second list.
|
||||
- Same as the C(all) Python function.
|
||||
options:
|
||||
_input:
|
||||
description: List.
|
||||
type: list
|
||||
elements: raw
|
||||
required: True
|
||||
_superset:
|
||||
description: List to test against.
|
||||
type: list
|
||||
elements: raw
|
||||
required: True
|
||||
EXAMPLES: |
|
||||
big: [1,2,3,4,5]
|
||||
sml: [3,4]
|
||||
issmallinbig: '{{ small is subset(big) }}'
|
||||
RETURN:
|
||||
_value:
|
||||
description: Returns C(True) if the specified list is a subset of the provided list, C(False) otherwise.
|
||||
type: boolean
|
@ -0,0 +1,28 @@
|
||||
DOCUMENTATION:
|
||||
name: superset
|
||||
author: Ansible Core
|
||||
version_added: "2.4"
|
||||
short_description: is the list a superset of this other list
|
||||
aliases: [issuperset]
|
||||
description:
|
||||
- Validate if the first list is a super set (includes) the second list.
|
||||
- Same as the C(all) Python function.
|
||||
options:
|
||||
_input:
|
||||
description: List.
|
||||
type: list
|
||||
elements: raw
|
||||
required: True
|
||||
_subset:
|
||||
description: List to test against.
|
||||
type: list
|
||||
elements: raw
|
||||
required: True
|
||||
EXAMPLES: |
|
||||
big: [1,2,3,4,5]
|
||||
sml: [3,4]
|
||||
issmallinbig: '{{ big is superset(small) }}'
|
||||
RETURN:
|
||||
_value:
|
||||
description: Returns C(True) if the specified list is a superset of the provided list, C(False) otherwise.
|
||||
type: boolean
|
@ -0,0 +1,24 @@
|
||||
DOCUMENTATION:
|
||||
name: truthy
|
||||
author: Ansible Core
|
||||
version_added: "2.10"
|
||||
short_description: Pythonic true
|
||||
description:
|
||||
- This check is a more Python version of what is 'true'.
|
||||
- It is the opposite of C(falsy).
|
||||
options:
|
||||
_input:
|
||||
description: An expression that can be expressed in a boolean context.
|
||||
type: string
|
||||
required: True
|
||||
convert_bool:
|
||||
description: Attempts to convert to strict python boolean vs normally acceptable values (C(yes)/C(no), C(on)/C(off), C(0)/C(1), etc).
|
||||
type: bool
|
||||
default: false
|
||||
EXAMPLES: |
|
||||
thisistrue: '{{ "any string" is truthy }}'
|
||||
thisisfalse: '{{ "" is truthy }}'
|
||||
RETURN:
|
||||
_value:
|
||||
description: Returns C(True) if the condition is not "Python truthy", C(False) otherwise.
|
||||
type: boolean
|
@ -0,0 +1,19 @@
|
||||
DOCUMENTATION:
|
||||
name: truthy
|
||||
author: Ansible Core
|
||||
version_added: "2.10"
|
||||
short_description: Is this an encrypted vault
|
||||
description:
|
||||
- Verifies if the input is an Ansible vault.
|
||||
options:
|
||||
_input:
|
||||
description: The possible vault.
|
||||
type: string
|
||||
required: True
|
||||
EXAMPLES: |
|
||||
thisisfalse: '{{ "any string" is ansible_vault }}'
|
||||
thisistrue: '{{ "$ANSIBLE_VAULT;1.2;AES256;dev...." is ansible_vault }}'
|
||||
RETURN:
|
||||
_value:
|
||||
description: Returns C(True) if the input is a valid ansible vault, C(False) otherwise.
|
||||
type: boolean
|
Loading…
Reference in New Issue