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?

asked Jun 24, 2019 at 5:00

1 Answer 1

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

answered Jun 24, 2019 at 15:18
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.