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

Note

This lookup plugin is part of the community.general collection (version 8.5.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. You need further requirements to be able to use this lookup plugin, see Requirements for details.

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

New in community.general 4.0.0

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.

Keyword parameters

This describes keyword parameters of the lookup. These are the values key1=value1, key2=value2 and so on in the following examples: lookup('community.general.random_words', key1=value1, key2=value2, ...) and query('community.general.random_words', key1=value1, key2=value2, ...)

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 Value

Key

Description

Return value

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.