I am trying to use ansible loop until the condition is met.
I can use until
if the output is only single line, however if the output is multiple lines, I will need to use stdout_lines
but fail to do so.
If output is single line:
- name: check on sync status
shell: some command
register: sync_status
until: sync_status.stdout == 'SSUS'
If output is multiple lines, then I try to use stdout_lines
- name: check on sync status
shell: some command
register: sync_status
until: item.stdout_lines == 'SSUS'
with_items: "{{ sync_status }}"
but I got variable undefined:
fatal: [xxxxxxx]: FAILED! => {
"msg": "'sync_status' is undefined"
}
I don't want to do it on seperate task because then the sync_status is registered on previous task , and I will be comparing the old status instead of the current status.
Kindly assist.
For example, given the file and the playbook
the task will fail
But, if you insert the string "SSUS" into the file before or during the testing the task will succeed, e.g.
Fit the parameters to your needs.
Q: "If the output is multiple lines, I will need to use stdout_lines."
A: Test the presence of the string in the list, e.g.