Ansible 原始模块交互

Ansible raw module interaction

提问人:Alex Deiwor 提问时间:11/16/2023 最后编辑:pynexjAlex Deiwor 更新时间:11/17/2023 访问量:28

问:

为了避免 XY 问题:我有三个设备(Master、J umphost、E ndpoint),我想确保 Jumphost 尝试在 Endpoint 上使用默认的 root/root user:password 登录。

  • Master 是一个 Ubuntu 全功能 linux。
  • Jumphost 是一个有限的发行版 linux。
  • Endpoint 是一个有限的发行版 linux。

为此,我有一本简单的剧本。

 - name: Check default user/password (root/root)
   expect:
       command: ssh -o StrictHostKeyChecking=no [email protected]
       responses:
         (?i)password: "root"
   register: result_5154
   when: "'jumphost' in inventory_hostname"

expect 的问题是没有安装 pexect

An exception occurred during task execution. To see the full traceback, use -vvv. The error was: ImportError: No module named pexpect
fatal: [jumphost -> None]: FAILED! => {"changed": false, "msg": "Failed to import the required Python library (pexpect) on jumphost's Python /usr/bin/python. Please read the module documentation and install it in the appropriate location. If the required library is installed, but Ansible is using the wrong Python interpreter, please consult the documentation on ansible_python_interpreter"}

所以我正在尝试使用 Ansible 原始模块,但它永远挂起(或超时到 10 秒),因为在尝试发送密码时,它正在等待进一步输入。

我知道这里还有另一个问题,那就是如何在没有安装像 sshpass 这样的应用程序的情况下发送 ssh 密码,但它可能是任何其他命令,它期望在初始命令之后输入。如何管理?

- name: Check default user/password (root/root)
  raw: ssh -o StrictHostKeyChecking=no [email protected]
  timeout: 10
  register: result_default_password
  when: "'jumphost' in inventory_hostname"

原始中的多行也不起作用

- name: Check default user/password (root/root)
  raw: |
    ssh -o StrictHostKeyChecking=no [email protected]
    root
  timeout: 10
  register: result_default_password
  when: "'jumphost' in inventory_hostname"

PS:在写这篇文章时,我意识到我可以创建一个SSH隧道并测试登录凭据?

python ansible pexpect raw

评论


答: 暂无答案