【问题标题】:Ansible stuck when running remote expect script运行远程期望脚本时,Ansible 卡住了
【发布时间】:2014-07-31 04:16:59
【问题描述】:

我正在创建一个 ansible 脚本来安装 ispconfig 而无需交互。我正在使用 expect 来处理 ispconfig 交互式安装 php 脚本。我正在使用 apt-get 版本的 expect 和最新版本的 ansible 将它安装在 Ubuntu 14.04 上。

运行期望脚本后 ansible 没有返回是怎么回事。

我使用的脚本如下:expect script on github

我从期望日志文件得到的输出是:

Stopping amavisd: amavisd-new.
Starting amavisd: amavisd-new.
 * Stopping ClamAV daemon clamd
   ...done.
 * Starting ClamAV daemon clamd
   ...done.
dovecot stop/waiting
dovecot start/running, process 30668
reload: Unknown instance:
 * Reloading nginx configuration nginx
   ...done.
Installation completed.
string detected

当我在远程主机上运行脚本时,它运行完美。通过 ansible 执行此脚本,但它不会返回。在 ansible 等待时,使用 -v 运行 ansible 不会显示任何日志信息。

ansible脚本的相关部分是:

  # as isconfig install is a interactive script we use expect to deal with that
  # by checking if ispconfig is present we make this an idempotent process  
  # if ispconfig absent the install will run
  - name: Check for installed ispconfig
    command: /usr/bin/test ! -e "/usr/local/ispconfig"
    register: ispconfig_absent
    ignore_errors: true

  - name: Copy expect script to configure ispconfig
    template: src=ispconfig.exp dest=/root/ispconfig.exp
    when: ispconfig_absent|success

  - name: set perm for script to configure ispconfig
    file: path=/root/ispconfig.exp mode=0750
    when: ispconfig_absent|success

  - name: configure ispconfig
    command: "/root/ispconfig.exp"
    when: ispconfig_absent|success

  - name: remove ispconfig configure script
    file: path=/root/ispconfig.exp state=absent
    when: ispconfig_absent|success

执行 ps aux 表明期望脚本已失效。 ansible 进程等待进程返回。

有什么线索可以做什么吗?

【问题讨论】:

  • 我遇到了确切的问题,您找到解决方案了吗?

标签: expect ansible


【解决方案1】:

好的,所以似乎 ansible 不喜欢期望脚本等。所以这是对我有用的解决方案(带有示例):

- name: run the expect script which will interactively install crashplan
  command: expect install_crashplan.expect {{ crashplan_backup_drive }} chdir=/opt/CrashPlan_test/CrashPlan-install
  register: command_result
  failed_when: "'CrashPlan has been installed' not in command_result.stdout"

如果您添加一个调试规则(您可能需要更改 failed_when 规则以强制它完成)并打印字典变量 command_result,您将看到它不包含任何错误并且在事实完备。但它仍然永远不会回来!?

    1234563如果您可以找到该字符串,则任务完成,否则失败。
  • 您还需要记住使用 expect 程序,而不是仅使用 script 模块运行脚本。如果期望脚本没有,这种保证返回码。

希望这对某人有所帮助!

干杯。

【讨论】:

猜你喜欢
  • 1970-01-01
  • 2017-05-22
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2021-08-13
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多