8

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.

Luke
  • 3,826
  • 8
  • 36
  • 40
  • 1
    The first thing to do is to update Ansible. There's virtually no reason why you should be on such an old version. – Michael Hampton Mar 14 '16 at 04:55
  • It's the out of the box version that comes with Ubuntu 14.04 LTS. I understand it's a bit dated but nothing in the Ansible manual in regards to the Supervisor module indicates I should update (apart from the group name thing which I'm not interested in). Granted, a newer version might have bug fixes but, what I'm trying seems pretty rudimentary that not a latest version should be able to handle it. – Luke Mar 14 '16 at 05:29
  • I'm _fairly_ sure you need Ansible 1.6 or later for this, as that's when group support was added. Even Red Hat is tracking the latest stable version (they're currently on 1.9.4), so I don't know what the deal is with Ubuntu here. Of course on Red Hat you could just use systemd and forget about all this supervisor stuff. – Michael Hampton Mar 14 '16 at 05:32
  • No worries. This is the documentation I'm going off: http://docs.ansible.com/ansible/supervisorctl_module.html – Luke Mar 14 '16 at 06:08
  • Right, and that's the very same page that notes you need 1.6! – Michael Hampton Mar 14 '16 at 06:09
  • No it doesn't. It says `Group support is only available in Ansible version 1.6 or later`. I don't need group support as I stated in my question. I assume that `program:process` is the name I'm targeting, not `program:` which would be the group. – Luke Mar 14 '16 at 06:21

1 Answers1

9

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.

tedder42
  • 853
  • 1
  • 9
  • 20
  • 2
    Thanks for that. Much appreciated, however, it doesn't make a difference. The `supervisorctl` task is still failing because it can't reference/find the `program:process`. This seems to be an issue in this Ansible module (and yes, I don't place my program definitions inside the `supervisord.conf` and they are loaded from external `conf` files). In the end I went with a simple Ansible command, bypassing the Supervisor module altogether: `command: supervisorctl -c /etc/supervisor/supervisord.conf restart` and this works perfectly. – Luke Mar 14 '16 at 21:51
  • does it work without the `-c`, @luke ? – tedder42 Mar 14 '16 at 22:29