Introduction to Ansible Transcripts
Chapter: Configuring Servers
Lecture: Installing PostgreSQL

Login or purchase this course to watch this video and the rest of the course contents.
0:00 How are we doing so far on our steps to take a look at some of the modules that we use in order to configure our server?
0:06 We said that first we were going to provision a couple of servers off DigitalOcean, which we did. Create a non-root group and user
0:12 that'd be our deployers group and deployer user which are set as variables so we could change the names if we wanted to.
0:18 We want to harden our server against malicious actors. We took just the absolute basic steps of updating
0:24 the system packages, putting in some firewall rules locking down the root user so that no one can log in directly
0:30 whether it be a password or even with a private key. Under the root user they can only log in under the deployer user.
0:36 You likely want to take many more steps and do more research about how to secure a web server but those are just some of the basic steps
0:42 that you're always going to want to take. Next we stood up a web server, installed Nginx and we wrote the absolute simplest custom
0:48 web server configuration that we could easily expand. And which we will expand in the next chapter to include a security certificate
0:54 that we can have HTTPS connections. To round out the scaffolding for this chapter we're going to install and configure the Postgres database.
1:01 And we want to check the database connection just do some very basic set up. For example, creating a database and creating
1:06 a separate Postgres user for that database. Let's give this a try. We're back in the base directory of our server config project
1:15 and let's go under roles/database and then under tasks. Now we already have a couple YAML files here because we set up the firewall roles
1:26 specifically for Postgres access only on our database server. Go back under main.yml. And we're going to include a new file
1:34 we'll just call this one postgresql.yml Save that and now let's create this file.
1:51 We'll start out by installing the system packages that we need for Postgres and if we wanted to run a Python application.
2:05 We'll use the apt module again and remember and we're going to list out a bunch of system packages but remember these will only get installed once
2:11 because Ansible always goes and checks to make sure that those packages are installed and if they are already installed
2:16 it's not going to do it over again. So it saves time on subsequent playbook routes. The name of the package is specified as a token.
2:29 And the items that will populate that token are the following packages.
2:46 And we'll need superuser privileges in order to install this. One thing to take note of here it's really easy to make a typo in a package name
2:54 so always check to make sure that you've typed in the appropriate packages. I actually just realized I had a h where there should be a g
3:00 which would cause this task to fail. Now this looks good. We want the psycopg2 package. We could save this, should be ready to run.
3:07 Head back up into the base project directory. Let's give our playbook a try.
3:30 Looks good. We should have these packages installed and now we can customize our Postgres configuration.


Talk Python's Mastodon Michael Kennedy's Mastodon