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

Note

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

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

Comments

case

string

The method for setting the case of each word in the passphrase.

Choices:

  • alternating

  • upper

  • lower ← (default)

  • random

  • capitalize

delimiter

string

The delimiter character between words.

Default: ” “

max_length

integer

Maximum length of words to make password.

Default: 9

min_length

integer

Minimum length of words to make password.

Default: 5

numwords

integer

The number of words.

Default: 6

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

Description

_raw

list / elements=string

A single-element list containing random words.

Returned: success

Authors

  • Thomas Sjögren (@konstruktoid)

Hint

Configuration entries for each entry type have a low to high priority order. For example, a variable that is lower in the list will override a variable that is higher up.