我正在尝试按this solution添加使用shell
模块和ssh-keyscan
来添加新创建的EC2实例的known_hosts文件的密钥。
在尝试按照该问题列出的多种方式执行此操作后,我最终只使用shell
模块运行了ssh-keyscan命令而没有附加。我从这项任务中得不到任何结果:
- name: accept new ssh fingerprints
shell: ssh-keyscan -H {{ item.public_ip }}
args:
executable: /bin/bash
with_items: "{{ ec2.instances }}"
register: keyscan
- debug: var=keyscan
此处的调试在stdout
和stdout_lines
中均未显示任何内容,stderr
和stderr_lines
注意:在尝试bash
模块默认为shell
(我的Linux Mint上的/bin/sh
shell)之后,我尝试使用dash
作为可执行文件运行VirtualBox的。但无论如何都是一样的。
我已经使用以下任务测试了shell命令,我在stdout
和stdout_lines
中看到了正确的输出:
- name: test the shell
shell: echo hello
args:
executable: /bin/bash
register: hello
- debug: var=hello
这里发生了什么?在终端中运行ssh-keyscan
(而不是通过Ansible)按预期工作。
编辑:查看调试的raw_params输出显示ssh-keyscan -H x.x.x.x
,并将其复制并粘贴到终端按预期工作。
答案 0 :(得分:0)
答案是第一次时间不起作用。在研究another method时,我偶然发现了ansible中的retries
关键字,允许重试任何命令。我尝试了这个,并在重试循环中尝试编号2它正在工作。