在 RedHat7 上使用 pexpect 是否仍然适用,或者是否有执行命令并响应提示的替代方法? [英] Is it still applicable to use pexpect on RedHat7 or is there alternative way to Executes a command and responds to prompts?
问题描述
我正在尝试在 Redhat7 中使用 pexpect 来实现 ansible,但我无法安装它.我只得到 pexpect.noarch 2.3-11.el7 @RHEL7 版本.或者 pexpect 是否有执行命令并响应提示的替代方法?
I'm trying to use pexpect in Redhat7 for ansible but I wasn't able to install it. I was only getting pexpect.noarch 2.3-11.el7 @RHEL7 version. Or is there a alternative for pexpect to Executes a command and responds to prompts?
推荐答案
看起来 RHEL7 附带的 pexpect
Python 模块的版本对于 Ansible 来说太旧了(RHEL7 有 pexpect 2.3,而 Ansible想要 3.3 或更高).您最好的选择可能是使用 shell
或 command
模块来运行 expect
;shell
模块:
It looks like the version of the pexpect
Python module shipped with RHEL7 is too old for Ansible (RHEL7 has pexpect 2.3, and Ansible wants 3.3 or greater). Your best option is probably to use the shell
or command
module to run expect
; there is an example of this in the 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
这篇关于在 RedHat7 上使用 pexpect 是否仍然适用,或者是否有执行命令并响应提示的替代方法?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!