在RedHat7上使用PEXPPECT还是可以执行命令并响应提示的其他方法是否适用



我正在尝试将redhat7中的pexpect用于Ansible,但我无法安装它。我只得到pexpect.noarch 2.3-11.el7 @rhel7版本。还是Pexpect可以执行命令并响应提示?

有其他选择。

看起来,用Rhel7运送的pexpect Python模块的版本太旧了(Rhel7具有PEXPECT 2.3,并且Ansible想要3.3或更高(。您最好的选择可能是使用shellcommand模块运行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 hostn"
    expect "pxeboot.n12"
    send "n"
    exit 0
  args:
    executable: /usr/bin/expect
  delegate_to: localhost

最新更新