在RedHat7上使用pexpect还是适用的还是执行命令并响应提示的替代方法?

时间:2019-05-14 09:01:41

标签: ansible pexpect

我试图在Redhat7中使用pexpect进行ansible,但无法安装它。我只得到pexpect.noarch 2.3-11.el7 @ RHEL7版本。还是pexpect可以执行命令并响应提示?

1 个答案:

答案 0 :(得分:1)

RHEL7附带的pexpect Python模块的版本对于Ansible来说太旧了(RHEL7具有pexpect 2.3,而Ansible需要3.3或更高)。最好的选择可能是使用shellcommand模块来运行expectdocumentation for the shell module中有一个示例:

# 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