community.general.random_words lookup – Return a number of random words
Note
This lookup plugin is part of the community.general collection (version 10.0.1).
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 |
---|---|
The method for setting the case of each word in the passphrase. Choices:
|
|
The delimiter character between words. Default: |
|
Maximum length of words to make password. Default: |
|
Minimum length of words to make password. Default: |
|
The number of words. Default: |
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 |
---|---|
A single-element list containing random words. Returned: success |