它仍然适用于在 RedHat7 上使用 pexpect 还是有替代方法来执行命令并响应提示?

Ric*_*ros 2 pexpect ansible

我尝试在 Redhat7 中使用 pexpect for ansible,但无法安装它。我只得到 pexpect.noarch 2.3-11.el7 @RHEL7 版本。或者 pexpect 是否有替代方法来执行命令并响应提示?

lar*_*sks 5

看起来pexpectRHEL7 附带的 Python 模块版本对于 Ansible 来说太旧了(RHEL7 有 pexpect 2.3,而 Ansible 需要 3.3 或更高版本)。您最好的选择可能是使用shellorcommand模块来运行expectshell模块的文档中有一个这样的示例:

# You can use shell to run other executables to perform actions inline
- name: Run expect to wait for a successful PXE boot via out-of-band CIMC
  shell: |
    set timeout 300
    spawn ssh admin@{{ cimc_host }}

    expect "password:"
    send "{{ cimc_password }}\n"

    expect "\n{{ cimc_name }}"
    send "connect host\n"

    expect "pxeboot.n12"
    send "\n"

    exit 0
  args:
    executable: /usr/bin/expect
  delegate_to: localhost
Run Code Online (Sandbox Code Playgroud)