random¶
Collection Note
This module is part of the ansible.builtin collection. To install the collection, use:
Added in version2.6.
Synopsis¶
- Use the input to either select a random element of a list or generate a random number.
Parameters¶
| Parameter | Defaults / Choices | Comments |
|---|---|---|
| _input raw required |
A number or list/sequence, if it is a number it is the top bound for random number generation, if it is a sequence or list, the source of the random element selected. | |
| seed str |
If specified use a pseudo random selection instead (repeatable). | |
| start int |
Bottom bound for the random number/element generated. | |
| step int |
Default: 1 |
Subsets the defined range by only using this value to select the increments of it between start and end. |
Examples¶
# can be any item from the list
random_item: "{{ ['a','b','c'] | random }}"
# cron line, select random minute repeatable for each host
"{{ 60 | random(seed=inventory_hostname) }} * * * * root /script/from/cron"
Return Values¶
| Key | Data Type | Description | Returned |
|---|---|---|---|
| _value | raw | Random number or list element. |