Introduction to Ansible Transcripts
Chapter: Deployments
Lecture: Updating Config Files with the lineinfile Module

Login or purchase this course to watch this video and the rest of the course contents.
0:00 We set up the WSGI server and now have Nginx serving as a reverse proxy. We grabbed our application dependencies from PyPI.
0:07 One more step that we want to do to make sure that we can actually have a two-server deployment is tweak our database settings.
0:13 Right now, Postgres, very same default settings only allow local connections. And so, we just want to update the configuration
0:20 so that our web server can connect to the database server. We're just going to tweak one line in our Postgres configuration
0:26 and that will do it for our deployment. So our web server is set so let's move into roles/database/tasks. And we'll add one task here.
0:44 Allow connections from our web server. Could of used the lineinfile module and the lineinfile module checks to see if a specific line is in a file
0:52 and if it is skips the step if it's not I'll make sure that line gets in there. It's super handy for tweaking configuration files
0:58 and especially if you don't want to create an entire template file yourself. First, we specify the path to the file that we want to modify.
1:12 And modify the pg_hba.conf Postgres figuration file. We want this line to be present where we say insert this after this line. And our line should be
1:37 and normally you'd set up a variable for this but in this case we're just going to put the IP address of our web server and we're going to trust it.
1:44 Course, you should modify this for your own purposes but this is just an example so that you will be able to use the lineinfile module as a task.
1:51 Finally, we need superuser privileges so set become yes on this. Now, I've tested this out and I have two separate windows.
2:00 In the bottom window, we're going to log into the server. Let's take a look at that configuration file.
2:23 So when we execute our playbook we are then going to have a line that is inserted here into the default configuration that allows our web server
2:30 to connect to the database. We'll just start at the task. Now we see that using the lineinfile module we can populate text into any files that we want
2:42 whether that's a configuration file, readme file we don't always need to use templates to accomplish populating information into files.
2:49 Again, for your own deployments you're going to want to customize everything that we've done here
2:53 including adding additional security settings for Postgres. These examples were really to show you what you could do
2:58 with Ansible rather than teach you how to configure a Postgres database or set up a Python application.
3:03 This was really just an example to learn more about Ansible.

Talk Python's Mastodon Michael Kennedy's Mastodon