我试图在Redhat7中使用pexpect进行ansible,但无法安装它。我只得到pexpect.noarch 2.3-11.el7 @ RHEL7版本。还是pexpect可以执行命令并响应提示?
答案 0 :(得分:1)
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