March 2019
Intermediate to advanced
412 pages
9h 49m
English
Similar to the random filter, the shuffle filter can be used to produce randomized results. Unlike the random filter, which selects one random choice from a list, the shuffle filter will shuffle the items in a sequence and return the full sequence:
---
- name: demo the filters
hosts: localhost
gather_facts: false
tasks:
- name: shuffle the cards
debug:
msg: "{{ ['Ace', 'Queen', 'King', 'Deuce'] | shuffle }}"
The output is shown in the following screenshot:

As expected, we see the whole list returned, but with the order shuffled.
Read now
Unlock full access