在shell模块中使用ssh-keyscan不会在Ansible中生成任何输出

时间:2017-11-07 21:42:43

标签: ansible ansible-2.x

我正在尝试按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

此处的调试在stdoutstdout_lines中均未显示任何内容,stderrstderr_lines

中均未显示任何内容

注意:在尝试bash模块默认为shell(我的Linux Mint上的/bin/sh shell)之后,我尝试使用dash作为可执行文件运行VirtualBox的。但无论如何都是一样的。

我已经使用以下任务测试了shell命令,我在stdoutstdout_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,并将其复制并粘贴到终端按预期工作。

1 个答案:

答案 0 :(得分:0)

答案是第一次时间不起作用。在研究another method时,我偶然发现了ansible中的retries关键字,允许重试任何命令。我尝试了这个,并在重试循环中尝试编号2它正在工作。