title: How to stop a service if it is running using Ansible
body: <p>I would like to know the best way to stop a service in Ansible only if the service is running. I wish to do something along these lines </p>
  
  <pre><code>- name: Check to see if Jenkins is running
    service:
      name: jenkins
      state: status
    register: jenkins_running_status
  
  - name: Stop Jenkins if it is running
    service:
      name: jenkins
      state: stopped
    when: jenkins_running_status == False
  </code></pre>
  
  <p>Obviously this does not work. I would like to know the best way to stop a service like Jenkins if only it is running. </p>