1

我有一个任务需要执行,直到标准输出中有某个字符串。bigip_command 的标准输出是一个列表(https://docs.ansible.com/ansible/latest/modules/bigip_command_module.html#return-values

    - name: Disable pool member
      bigip_command:
        commands: "tmsh show /sys connection ss-server-addr xx.xx.xx.xx ss-server-port 8080"
        provider:
          user: "xx"
          password: "xxx"
          server_port: xx
          server: xxx
      delegate_to: localhost
      register: result
      until: "'Total records returned: 0' in result.stdout"<br><br>

输出是:

失败 - 重试:禁用池成员(剩余 3 次重试)

但是返回的总记录数:0 在 result.stdout 中。

使用调试输出为:

    - name: debug
      debug:
        msg: "{{ result.stdout }}"

输出:

    ok: [xxx] => {
        "msg": [
            "Sys::Connections\nTotal records returned: 0"
       ]
    }
4

1 回答 1

0

请参阅重试任务直到满足条件。尝试

- name: Disable pool member
  vars:
    my_regex: 'Total records returned: 0'
  bigip_command:
    commands: "yyy"
    user: "xx"
    password: "xxx"
    server_port: xx
    server: xxx
  delegate_to: localhost
  register: result
  until: result.stdout is search(my_regex)
  retries: 5
  delay: 10

(未测试)

于 2019-12-19T16:20:54.000 回答