【发布时间】:2019-05-14 09:01:40
【问题描述】:
我正在尝试在 Redhat7 中将 pexpect 用于 ansible,但我无法安装它。我只得到 pexpect.noarch 2.3-11.el7 @RHEL7 版本。或者 pexpect 是否有替代方法来执行命令并响应提示?
【问题讨论】:
我正在尝试在 Redhat7 中将 pexpect 用于 ansible,但我无法安装它。我只得到 pexpect.noarch 2.3-11.el7 @RHEL7 版本。或者 pexpect 是否有替代方法来执行命令并响应提示?
【问题讨论】:
看起来 RHEL7 附带的 pexpect Python 模块的版本对于 Ansible 来说太旧了(RHEL7 有 pexpect 2.3,而 Ansible 需要 3.3 或更高版本)。您最好的选择可能是使用shell 或command 模块来运行expect; documentation 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
【讨论】: