1

I need to check command stdout with a regex pattern in until loop. When I using regex_search to display debug msg all works fine:

    - name: Checking if node is ready
      shell: "kubectl --kubeconfig {{kubeconf}} get nodes"
      register: k_output

    - debug:
        msg: "{{k_output.stdout | regex_search(node_hostname | string + '\\s+Ready')}}"

The message is

ok: [any_node_hostname] => {
    "msg": "any_node_hostname   Ready"
}

But if I trying to use that construction inside until conditional statement task fails with syntax error.

    - set_fact:
        regexp_pattern: "{{node_hostname | string + '\\s+Ready'}}"

    - debug:
        msg: "{{regexp_pattern}}"

    - name: Checking if node is ready
      shell: "kubectl --kubeconfig {{kubeconf}} get nodes"
      register: k_output
      until: "{{k_output.stdout | regex_search(regexp_pattern)}}" != ""
      retries: 5
      delay: 10

The same behaviour without set_fact when I just copying and pasting full string {{k_output.stdout | regex_search(node_hostname | string + '\\s+Ready')}} to until conditional statement. So, how can I use regex_search or something that fits this case with until?

lexadler
  • 245
  • 5
  • 13

1 Answers1

2

you have syntax error at until: statement : you must not quote the vars in expression, like in example here : Retrying a task until a condition is met

    until: k_output.stdout | regex_search(regexp_pattern) != ""

I hope this will help

tassinp
  • 734
  • 4
  • 8