title: How to run supervisor with Ansible?
body: <p>I've got a server on which <a href="http://supervisord.org" rel="nofollow">Supervisord</a> is managing my processes. I normally start supervisord with the following command:</p>
  
  <pre><code>sudo /var/www/imd/venv/bin/supervisord -c /var/www/imd/deploy/supervisord.conf
  </code></pre>
  
  <p>I'm now trying to set things up with <a href="https://www.ansible.com/" rel="nofollow">Ansible</a>, but I'm unsure of how I should start Ansible. I can of course do it using something like:</p>
  
  <pre><code>- name: run supervisord
    command: "/var/www/imd/venv/bin/supervisord -c /var/www/imd/deploy/supervisord.conf"
  </code></pre>
  
  <p>This works, but only the first time that you run it. Second time you run the same script supervisord is of course already running, which causes the following error:</p>
  
  <blockquote>
    <p>TASK [run supervisord]
    ******************************************************* fatal: [ansible-test1]: FAILED! => {"changed": true, "cmd":
    ["/var/www/imd/venv/bin/supervisord", "-c",
    "/var/www/imd/deploy/supervisord.conf"], "delta": "0:00:00.111700",
    "end": "2016-06-03 11:57:38.605804", "failed": true, "rc": 2, "start":
    "2016-06-03 11:57:38.494104", "stderr": "Error: Another program is
    already listening on a port that one of our HTTP servers is configured
    to use.  Shut this program down first before starting
    supervisord.\nFor help, use /var/www/imd/venv/bin/supervisord -h",
    "stdout": "", "stdout_lines": [], "warnings": []}</p>
  </blockquote>
  
  <p>Does anybody know how I can correctly run supervisord with Ansible? All tips are welcome!</p>
  
  <p>[EDIT]</p>
  
  <p>Because the solution in the answer by mbarthelemy doesn't work for socket files I now managed to get it working with the following:</p>
  
  <pre><code>- name: run supervisord
    shell: if [ ! -S /var/run/supervisor.sock ]; then sudo /var/www/imd/venv/bin/supervisord -c /var/www/imd/deploy/supervisord.conf; fi
  </code></pre>
  
  <p>This of course is not very "ansibleish". If anybody has a real Ansible-based solution that would still be really welcome.</p>