title: looping over shell commands in ansible
body: <p>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":</p>
  
  <pre><code>for iterations=0; iterations &lt; 10; iterations++ {
      status = systemctl is-active myservice
          if (status == active)
              break
          sleep 3s
      }
  }
  if status != active {
      failure: exit playbook
  }
  </code></pre>
  
  <p>Seems like in ansible playbook i can iterate over the results of shell command but after looking into "loops" in documentation:
  <a href="http://docs.ansible.com/ansible/latest/playbooks_loops.html#iterating-over-the-results-of-a-program-execution" rel="nofollow noreferrer">http://docs.ansible.com/ansible/latest/playbooks_loops.html#iterating-over-the-results-of-a-program-execution</a>
  I couldn't find how to repeat command itself, based on output. Can it be done?</p>