Reputation: 45
I have to restart systemd unit in my playbook and wait until service is active, so my "check and wait" logic must be as following in "pseudo-code":
for iterations=0; iterations < 10; iterations++ {
status = systemctl is-active myservice
if (status == active)
break
sleep 3s
}
}
if status != active {
failure: exit playbook
}
Seems like in ansible playbook i can iterate over the results of shell command but after looking into "loops" in documentation: http://docs.ansible.com/ansible/latest/playbooks_loops.html#iterating-over-the-results-of-a-program-execution I couldn't find how to repeat command itself, based on output. Can it be done?
Upvotes: 1
Views: 3777
Reputation: 68329
There are do-until loops in Ansible:
- shell: systemctl is-active myservice
register: results
until: results | success
retries: 10
delay: 3
Upvotes: 4