community.general.random_words 查询 – 返回多个随机单词

注意

此查询插件是 community.general 集合 (版本 10.1.0) 的一部分。

如果您使用的是 ansible 包,则可能已安装此集合。它不包含在 ansible-core 中。要检查是否已安装,请运行 ansible-galaxy collection list

要安装它,请使用: ansible-galaxy collection install community.general。您需要其他要求才能使用此查询插件,请参阅 需求 获取详细信息。

要在 playbook 中使用它,请指定: community.general.random_words

community.general 4.0.0 中的新增功能

概要

  • 返回多个随机单词。输出可以例如用于密码。

  • 查看 https://xkcd.com/936/ 获取背景信息。

需求

以下需求在执行此查询的本地控制器节点上是必需的。

关键字参数

这描述了查询的关键字参数。这些是在以下示例中的值 key1=value1key2=value2 等: lookup('community.general.random_words', key1=value1, key2=value2, ...)query('community.general.random_words', key1=value1, key2=value2, ...)

参数

注释

case

字符串

设置密码短语中每个单词大小写的方法。

选项

  • "交替"

  • "大写"

  • "小写" ← (默认)

  • "随机"

  • "首字母大写"

delimiter

字符串

单词之间的分隔符字符。

默认值: " "

max_length

整数

生成密码的单词的最大长度。

默认值: 9

min_length

整数

生成密码的单词的最小长度。

默认值: 5

numwords

整数

单词的数量。

默认值: 6

示例

- 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

返回值

描述

返回值

列表 / 元素=字符串

包含随机单词的单元素列表。

返回: 成功

作者

  • Thomas Sjögren (@konstruktoid)

提示

每个条目类型的配置条目具有从低到高的优先级顺序。例如,列表中较低的变量将覆盖较高的变量。