Introduction to Ansible Transcripts
Chapter: Configuring Servers
Lecture: The template Module for Configuration Files
0:00 We installed Nginx with Ansible. Now we're going to create a very simple custom configuration using a template. And then in the next chapter
0:08 we're going to use that template as the base for a much more complicated custom configuration. Head back under roles/webserver/tasks/nginx.yaml.
0:18 We are going to write out a custom Nginx configuration. We use the template module. The source is going to be nginx_conf.j2
0:33 within our Templates directory for this role. The destination will be the configuration directory for Nginx on the remote servers that we configure.
0:41 That's under etc/nginx_conf.d And we'll call it app.conf for now. Normally, we would configure this with our custom app name
0:49 but we're not pulling a specific application now so we can modify that later. We need to be a superuser to do this
0:55 because that's a protected directory. and now we can save this file and we want to go under a templates directory. Currently empty
1:03 I'll create a very bare bones Nginx.conf.j2 file we're just going to tell it to listen on port 80
1:11 which it already does so its not going to change its behavior in anyway but this will at least provide us
1:16 a basic template file that we can then modify later. Save that. Lets give it a try.
1:38 How do we know the configuration has been applied on the server we can log in and take a look at it. SSH with your private key
1:47 deployer@ and then the IP address of your web server. We're going to take a look under the Nginx configuration directory
1:58 now we see when we list the contents of app.conf we get server listen on port 80 and that's our configuration.
2:07 Now if we refresh the page its still listening on port 80 so even though we've updated our configuration hasn't changed
2:13 the behavior of the server at all. Now we have a very basic Nginx configuration with a template that we can put on any remote server
2:19 and we can expand upon it in order to add HTTPS or other custom configurations such as if we're going to have it serve as a reverse proxy
2:26 for a Python web application server we take this as our base and use it for more complicated configurations.