max is a Jinja2 filter, used to return the largest value in an array (also known as a list). The min filter is used to return the lowest value.Let's say you are using the vars plugin to create an array of integers.
vars:
integers:
- 2
- 4
- 3
- 1
The debug module can be used to output the entire array.
- name: output the contents of the 'integers' array
debug:
var: integers
Which should return the following.
TASK [output the contents of the 'integers' array]
ok: [server1.example.com] => {
"integers": [
"2"
"4",
"3",
"1"
]
}
The max filter can be used to get the largest value from the array.
- name: output the max value in the 'integers' array
debug:
var: integers | max
Which should return the following.
TASK [output the max value in the 'integers' array]
ok: [server1.example.com] => {
"integers | max": "4"
}