【问题标题】:Is it still applicable to use pexpect on RedHat7 or is there alternative way to Executes a command and responds to prompts?在 RedHat7 上使用 pexpect 是否仍然适用,或者是否有其他方法可以执行命令并响应提示?
【发布时间】:2019-05-14 09:01:40
【问题描述】:

我正在尝试在 Redhat7 中将 pexpect 用于 ansible,但我无法安装它。我只得到 pexpect.noarch 2.3-11.el7 @RHEL7 版本。或者 pexpect 是否有替代方法来执行命令并响应提示?

【问题讨论】:

    标签: ansible pexpect


    【解决方案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
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2020-03-07
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2020-12-28
      相关资源
      最近更新 更多