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=value1、key2=value2 等等,在以下示例中:lookup('community.general.random_words', key1=value1, key2=value2, ...) 和 query('community.general.random_words', key1=value1, key2=value2, ...)
| 参数 | 注释 | 
|---|---|
| 用于设置密码中每个单词大小写的方法。 选项 
 | |
| 单词之间的分隔符字符。 默认:  | |
| 构成密码的单词的最大长度。 默认:  | |
| 构成密码的单词的最小长度。 默认:  | |
| 单词的数量。 默认:  | 
示例
- 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
返回值
| 键 | 描述 | 
|---|---|
| 包含随机单词的单元素列表。 返回: 成功 | 
