Introduction to Ansible Transcripts
Chapter: Deployments
Lecture: Configuring Supervisor with the service and pause Modules

Login or purchase this course to watch this video and the rest of the course contents.
0:00 Let's set up our WSGI server, Green Unicorn which will run our Python application and will be able to pull all of the pieces together
0:07 restart Nginx, actually see our application up and running. Head back into roles/webserver/tasks/main.yml.
0:17 This time we're going to have a new file, wsgi.yml. Create that file, wsgi.yml. And the way that we're going to run this
0:30 is we're going to have Supervisor a system process that is going to start and stop Green Unicorn. Very standard way of setting up WSGI servers
0:40 in the Python ecosystem. First thing we need is to ensure that Supervisor is installed. And then we need to create a Supervisor configuration.
0:56 We're going to create this in a template. But we'll head into that after we finish these tasks.
1:16 And in previous versions of Supervisor on Ubuntu 16.04 there was a bug with it reloading and properly restarting Supervisor.
1:23 You needed to explicitly stop and then restart the server. I'm going to show you this now because we can use the pause module
1:30 to accomplish this. This can be handy in other situations where you need to pause the script for a couple seconds to allow something to take effect.
1:37 So we'll have three tasks here.
1:55 And we use the pause module and specify a number of seconds to pause. One more concept to introduce which you don't necessarily need to use
2:13 but can be nice to have in some situations. This is the equivalent of a signal in the database where we can call something else
2:18 when a certain action happens. So we can set notify on our tasks. We can call another task. So we're going to call the restart Nginx task.
2:28 And we typically store these under the handlers directory. So one more directory if you move up into web server make a directory for handlers
2:40 and we're just going to write a single task within main.yml. This is one way to cut down on boiler plate code. If you need to restart Nginx all over
2:59 restart a service, perform some action all over your playbook you can simply add notify and then the name of a handler in your playbook
3:06 and cut down on the boiler plate code. And save that file and let's move into templates. We just need to create our
3:12 Supervisor configuration template file. Just name this supervisor_app.conf.j2 'cause that's what we called it as a source file
3:22 and then we just use the standard Supervisor configuration format. We have a app name for our program to uniquely identify our program.
3:31 We want to run a command. We reuse our existing variables.


Talk Python's Mastodon Michael Kennedy's Mastodon