Ansible has difficulty restarting Supervisor

I'm trying to restart Supervisor through my Ansible Playbook but I seem to be stumbling into an issue with the supervisor module for Ansible.

In my Supervisor config I have defined a program:

[program:process]
process_name=%(program_name)s_%(process_num)02d
command=/home/box1/workers/bin/process
numprocs=64
directory=/home/box1/workers/bin
autostart=true
autorestart=true
startretries=5
stderr_logfile=/tmp/%(program_name)s-err.log
stdout_logfile=/tmp/%(program_name)s-out.log
user=root

And this works fine. However, when I try to restart Supervisor through Ansible I get the following error:

failed: [box1] => {"failed": true}
msg: program:process: ERROR (no such process)
program:process: ERROR (no such process)

My Ansible task configuration looks like this:

- name: Restart Supervisor
  sudo: yes
  supervisorctl: name=program:process state=restarted config=/etc/supervisor/supervisord.conf

For the name parameter I have tried program:process, program, program: and process but none seem to work. I'm currently on Ansible 1.5.4.


Solution 1:

The supervisorctl Ansible module does not support the reload command (see here), which is needed for supervisor to pick up new configuration entries.

You can do it yourself like this:

- command: supervisorctl reread
  sudo: yes
- supervisorctl: name=program:process state=restarted config=/etc/supervisor/supervisord.conf
  sudo: yes

The documentation on reload/reread/update/restart seems to be missing, and this blog post is out of date; you can experiment to make sure reload does what you expect.

Finally, don't put your program definitions in supervisord.conf. Instead, put them as individual files in /etc/supervisor/conf.d/*.conf. That makes installation and maintenance much easier.