【问题标题】:Using ssh-keyscan in shell module does not produce any output in Ansible在 shell 模块中使用 ssh-keyscan 不会在 Ansible 中产生任何输出
【发布时间】:2017-11-07 21:42:42
【问题描述】:

我正在尝试关注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 模块默认为/bin/sh 这是我的Linux Mint VirtualBox 上的dash shell 之后显示。但无论如何都是一样的。

我已经使用以下任务测试了 shell 命令,并且在 stdoutstdout_lines 中看到了正确的输出:

- name: test the shell
  shell: echo hello
  args:
    executable: /bin/bash
  register: hello
- debug: var=hello

这里发生了什么?在终端(不是通过 Ansible)中运行 ssh-keyscan 可以按预期工作。

编辑:查看调试的 raw_params 输出显示 ssh-keyscan -H x.x.x.x 并将其复制并粘贴到终端中按预期工作。

【问题讨论】:

  • 那么,Ansible 执行的确切的命令是什么?当您交互式地运行这个确切的命令时,结果是什么?在您的系统上检查不动产不是比在 StackOverflow 上更快更容易吗?
  • 我已经在调试中查看了运行 ssh-keyscan -H x.x.x.x 的 raw_params 输出,并将其复制并粘贴到终端中并按预期工作
  • 也许你看过,但SO上没有人看过,那你为什么指望别人知道?
  • 我没有意识到这不是很清楚,没想到其他人也知道......对不起,我编辑了这个问题

标签: ansible ansible-2.x


【解决方案1】:

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

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2022-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-01-07
    • 1970-01-01
    • 2021-11-15
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多