community.general.random_words – Return a number of random words

Note

This plugin is part of the community.general collection (version 4.2.0).

You might already have this collection installed if you are using the ansible package. It is not included in ansible-core. To check whether it is installed, run ansible-galaxy collection list.

To install it, use: ansible-galaxy collection install community.general.

To use it in a playbook, specify: community.general.random_words.

New in version 4.0.0: of community.general

Synopsis

  • Returns a number of random words. The output can for example be used for passwords.

  • See https://xkcd.com/936/ for background.

Requirements

The below requirements are needed on the local controller node that executes this lookup.

Parameters

Parameter Choices/Defaults Configuration Comments
case
string
    Choices:
  • alternating
  • upper
  • lower ←
  • random
  • capitalize
The method for setting the case of each word in the passphrase.
delimiter
string
Default:
" "
The delimiter character between words.
max_length
integer
Default:
9
Maximum length of words to make password.
min_length
integer
Default:
5
Minimum length of words to make password.
numwords
integer
Default:
6
The number of words.

Examples

- name: Generate password with default settings
  ansible.builtin.debug:
    var: lookup('community.general.random_words')
  # Example result: 'traitor gigabyte cesarean unless aspect clear'

- name: Generate password with six, five character, words
  ansible.builtin.debug:
    var: lookup('community.general.random_words', min_length=5, max_length=5)
  # Example result: 'brink banjo getup staff trump comfy'

- name: Generate password with three capitalized words and the '-' delimiter
  ansible.builtin.debug:
    var: lookup('community.general.random_words', numwords=3, delimiter='-', case='capitalize')
  # Example result: 'Overlabor-Faucet-Coastline'

- name: Generate password with three words without any delimiter
  ansible.builtin.debug:
    var: lookup('community.general.random_words', numwords=3, delimiter='')
  # Example result: 'deskworkmonopolystriking'
  # https://www.ncsc.gov.uk/blog-post/the-logic-behind-three-random-words

Return Values

Common return values are documented here, the following are the fields unique to this lookup:

Key Returned Description
_raw
list / elements=string
success
A single-element list containing random words.



Authors

  • Thomas Sjögren (@konstruktoid)