【发布时间】:2020-05-06 02:38:24
【问题描述】:
我正在尝试运行一个任务来执行 known_hosts 模块,其中包含一个关键条目列表。问题是我不断收到以下错误,即使变量在使用debug 时有数据。
The task includes an option with an undefined variable. The error was: 'item' is undefined
我有以下任务来注册 ssh-keyscan 输出的变量
- name: keyscan platform hosts
shell: "ssh-keyscan ssh.{{ item }}"
register: "platform_ssh_host_keys"
loop:
- "one.example.com"
- "two.example.com"
当我运行以下调试时,我得到包含密钥的标准输出
- name: debug
debug:
var: item.stdout
with_items: "{{platform_ssh_host_keys.results}}"
但当我使用 known_hosts 运行它时,它会说 item 未定义。
- name: configure known_hosts
known_hosts:
path: "~/.ssh/known_hosts"
name: "ssh.{{ item.item }}"
key: "{{ item.stdout }}"
state: present
loop: "{{ platform_ssh_host_keys.results }}"
我不明白如何在 debug 中定义 item 而不是 known_hosts 任务。
【问题讨论】:
标签: ansible