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