当使用Ansible expect模块时,有时会遇到响应被重复反馈的问题。这通常是因为正则表达式的问题导致匹配到多个响应。我们可以在expect的handler中添加跳出循环的语句来解决这个问题。以下是示例代码:
name: Expect example expect: command: some_command responses: 'password': 'my_password' timeout: 5 echo: yes handlers: - name: password_corrected expect: 'password_corrected' echo: no ignore_errors: true run_once: true notify: stop_loop
handlers: