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